switched from crossbeam to flume, for async support + fixed Instance::report_err() and Instance::new_connection_join_namespace()
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crossbeam::channel::{Sender, Receiver};
|
||||
use flume::{Sender, Receiver};
|
||||
use tracing::{trace, debug, info, warn, error};
|
||||
|
||||
use crate::id::Namespace;
|
||||
|
||||
@@ -2,7 +2,7 @@ use core::fmt;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::create_dir;
|
||||
use std::{thread, vec};
|
||||
use crossbeam::channel::{self, bounded, Receiver, Sender};
|
||||
use flume::{bounded, Receiver, Sender, unbounded};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tracing::{debug, error, info, trace, warn, Instrument};
|
||||
use uuid::Uuid;
|
||||
@@ -69,7 +69,7 @@ pub struct Instance {
|
||||
// the namespace of the instance itself
|
||||
// TODO: set to a random uuid
|
||||
pub self_namespace: Arc<Mutex<Namespace>>,
|
||||
pub op_tx: channel::Sender<Operation>,
|
||||
pub op_tx: Sender<Operation>,
|
||||
threads: Arc<Mutex<Vec<(u32, String)>>>,
|
||||
next_thread_id: Arc<Mutex<u32>>,
|
||||
give_msg_wait: Arc<Mutex<HashMap<MizeId, Vec<Sender<ItemData>>>>>,
|
||||
@@ -96,7 +96,7 @@ impl Instance {
|
||||
let namespace_pool_raw = StringPool::default();
|
||||
let connections = Arc::new(Mutex::new(Vec::new()));
|
||||
let subs = Arc::new(Mutex::new(HashMap::new()));
|
||||
let (op_tx, op_rx) = channel::unbounded();
|
||||
let (op_tx, op_rx) = unbounded();
|
||||
let give_msg_wait = Arc::new(Mutex::new(HashMap::new()));
|
||||
let create_msg_wait = Arc::new(Mutex::new(None));
|
||||
let namespace = Arc::new(Mutex::new(Namespace ( namespace_pool_raw.get("mize.default.namespace") )));
|
||||
@@ -368,13 +368,15 @@ impl Instance {
|
||||
}
|
||||
|
||||
pub fn new_connection_join_namespace(&self, tx: Sender<MizeMessage>) -> MizeResult<u64> {
|
||||
let conn_id = self.new_connection(&self, tx)?;
|
||||
let conn_id = self.new_connection(tx)?;
|
||||
|
||||
let ns_of_peer_str = self.get(format!("inst/con_by_id/{}/peer/0/config/namespace", conn_id))?.value_string()?;
|
||||
let ns_of_peer = self.namespace_from_string(ns_of_peer_str)?;
|
||||
|
||||
self.connection_set_namespace(conn_id, ns_of_peer.clone());
|
||||
self.set_namespace(ns_of_peer);
|
||||
|
||||
Ok(conn_id)
|
||||
}
|
||||
|
||||
pub fn connection_set_namespace(&self, conn_id: u64, namespace: Namespace) -> MizeResult<()> {
|
||||
@@ -428,8 +430,6 @@ impl Instance {
|
||||
|
||||
pub fn spawn(&mut self, name: &str, func: impl FnOnce() -> MizeResult<()> + Send + 'static) -> MizeResult<()> {
|
||||
|
||||
console_log!("in instance::spawn with wasm target");
|
||||
|
||||
let mut threads_inner = self.threads.lock()?;
|
||||
let mut next_thread_id = self.next_thread_id.lock()?;
|
||||
|
||||
@@ -552,7 +552,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
pub fn report_error(err: MizeError) {
|
||||
err.log()
|
||||
err.log();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use core::fmt;
|
||||
use std::rc::Rc;
|
||||
use crossbeam::channel::Sender;
|
||||
use flume::Sender;
|
||||
use std::sync::Arc;
|
||||
use tracing::trace;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crossbeam::channel::Receiver;
|
||||
use flume::Receiver;
|
||||
use tracing::{error, trace, warn};
|
||||
use std::borrow::BorrowMut;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
use clap::ArgMatches;
|
||||
use home::home_dir;
|
||||
use crossbeam::channel::bounded;
|
||||
use flume::bounded;
|
||||
use std::io::Read;
|
||||
|
||||
use mize::error::{IntoMizeResult, MizeError, MizeResult, MizeResultTrait};
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
||||
use tokio::net::{UnixListener as TokioUnixListener, UnixStream};
|
||||
use tokio::net::unix::{OwnedReadHalf, OwnedWriteHalf};
|
||||
use tokio::io::{Interest, AsyncReadExt, AsyncWriteExt};
|
||||
use crossbeam::channel::{Receiver, Sender, unbounded};
|
||||
use flume::{Receiver, Sender, unbounded};
|
||||
use ciborium::Value as CborValue;
|
||||
use tracing::{info, warn, debug};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user