Use tokio::sync::mpsc instead of crossfire::mpsc

Since tokio channels has blocking_recv now crossfire isn't needed
anymore.
macos-click-through
mforsb 3 years ago committed by Keith Simmons
parent 768a589576
commit 5c90f33e9e

@ -28,7 +28,6 @@ nvim-rs = { git = "https://github.com/KillTheMule/nvim-rs", branch = "master", f
tokio = { version = "1.1.1", features = ["full"] }
tokio-util = "0.6.7"
async-trait = "0.1.18"
crossfire = "0.1"
lazy_static = "1.4.0"
unicode-segmentation = "1.6.0"
log = "0.4.8"

@ -9,12 +9,12 @@ use std::process::Stdio;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use crossfire::mpsc::RxUnbounded;
use log::{error, info, warn};
use nvim_rs::UiAttachOptions;
use rmpv::Value;
use tokio::process::Command;
use tokio::runtime::Runtime;
use tokio::sync::mpsc;
use crate::channel_utils::*;
use crate::settings::*;
@ -157,7 +157,7 @@ fn connection_mode() -> ConnectionMode {
async fn start_neovim_runtime(
ui_command_sender: LoggingTx<UiCommand>,
ui_command_receiver: RxUnbounded<UiCommand>,
mut ui_command_receiver: mpsc::UnboundedReceiver<UiCommand>,
redraw_event_sender: LoggingTx<RedrawEvent>,
running: Arc<AtomicBool>,
) {
@ -297,13 +297,13 @@ async fn start_neovim_runtime(
}
match ui_command_receiver.recv().await {
Ok(ui_command) => {
Some(ui_command) => {
let input_nvim = input_nvim.clone();
tokio::spawn(async move {
ui_command.execute(&input_nvim).await;
});
}
Err(_) => {
None => {
ui_command_running.store(false, Ordering::Relaxed);
break;
}
@ -321,7 +321,7 @@ pub struct Bridge {
pub fn start_bridge(
ui_command_sender: LoggingTx<UiCommand>,
ui_command_receiver: RxUnbounded<UiCommand>,
ui_command_receiver: mpsc::UnboundedReceiver<UiCommand>,
redraw_event_sender: LoggingTx<RedrawEvent>,
running: Arc<AtomicBool>,
) -> Bridge {

@ -1,8 +1,8 @@
use std::fmt::Debug;
use std::sync::mpsc::{SendError, Sender};
use crossfire::mpsc::{SendError as TxError, TxUnbounded};
use log::trace;
use tokio::sync::mpsc;
#[derive(Clone)]
pub struct LoggingSender<T>
@ -35,7 +35,7 @@ pub struct LoggingTx<T>
where
T: Debug,
{
tx: TxUnbounded<T>,
tx: mpsc::UnboundedSender<T>,
channel_name: String,
}
@ -43,11 +43,11 @@ impl<T> LoggingTx<T>
where
T: Debug,
{
pub fn attach(tx: TxUnbounded<T>, channel_name: String) -> Self {
pub fn attach(tx: mpsc::UnboundedSender<T>, channel_name: String) -> Self {
Self { tx, channel_name }
}
pub fn send(&self, message: T) -> Result<(), TxError<T>> {
pub fn send(&self, message: T) -> Result<(), mpsc::error::SendError<T>> {
trace!("{} {:?}", self.channel_name, &message);
self.tx.send(message)
}

@ -8,8 +8,8 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::thread;
use crossfire::mpsc::RxUnbounded;
use log::{error, trace};
use tokio::sync::mpsc;
use crate::bridge::{EditorMode, GuiOption, RedrawEvent, WindowAnchor};
use crate::channel_utils::*;
@ -440,14 +440,14 @@ impl Editor {
}
pub fn start_editor(
redraw_event_receiver: RxUnbounded<RedrawEvent>,
mut redraw_event_receiver: mpsc::UnboundedReceiver<RedrawEvent>,
batched_draw_command_sender: LoggingSender<Vec<DrawCommand>>,
window_command_sender: LoggingSender<WindowCommand>,
) {
thread::spawn(move || {
let mut editor = Editor::new(batched_draw_command_sender, window_command_sender);
while let Ok(redraw_event) = redraw_event_receiver.recv_blocking() {
while let Some(redraw_event) = redraw_event_receiver.blocking_recv() {
editor.handle_redraw_event(redraw_event);
}
});

@ -31,7 +31,7 @@ extern crate lazy_static;
use std::sync::{atomic::AtomicBool, mpsc::channel, Arc};
use crossfire::mpsc::unbounded_future;
use tokio::sync::mpsc;
use bridge::start_bridge;
use cmd_line::CmdLineSettings;
@ -136,7 +136,7 @@ fn main() {
let running = Arc::new(AtomicBool::new(true));
let (redraw_event_sender, redraw_event_receiver) = unbounded_future();
let (redraw_event_sender, redraw_event_receiver) = mpsc::unbounded_channel();
let logging_redraw_event_sender =
LoggingTx::attach(redraw_event_sender, "redraw_event".to_owned());
@ -146,7 +146,7 @@ fn main() {
"batched_draw_command".to_owned(),
);
let (ui_command_sender, ui_command_receiver) = unbounded_future();
let (ui_command_sender, ui_command_receiver) = mpsc::unbounded_channel();
let logging_ui_command_sender = LoggingTx::attach(ui_command_sender, "ui_command".to_owned());
let (window_command_sender, window_command_receiver) = channel();

Loading…
Cancel
Save