chore: calm clippy wanring when using non send with Arc (#6018)

This commit is contained in:
Nathan.fooo 2024-08-20 17:07:54 +08:00 committed by GitHub
parent 70e96c01b3
commit 70d6351a6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 7 deletions

View File

@ -62,6 +62,7 @@ struct DartAppFlowyCore {
impl DartAppFlowyCore { impl DartAppFlowyCore {
fn new() -> Self { fn new() -> Self {
Self { Self {
#[allow(clippy::arc_with_non_send_sync)]
core: Arc::new(RwLock::new(None)), core: Arc::new(RwLock::new(None)),
handle: RwLock::new(None), handle: RwLock::new(None),
sender: RwLock::new(None), sender: RwLock::new(None),
@ -94,7 +95,6 @@ impl DartAppFlowyCore {
} }
} else { } else {
warn!("Failed to acquire read lock for sender"); warn!("Failed to acquire read lock for sender");
return;
} }
} }
} }
@ -207,7 +207,7 @@ impl Future for Runner {
.await; .await;
if let Some(ret) = ret { if let Some(ret) = ret {
let _ = ret.send(resp); let _ = ret.send(resp).await;
} }
}); });
}, },
@ -243,19 +243,23 @@ pub extern "C" fn set_log_stream_port(port: i64) -> i32 {
pub extern "C" fn link_me_please() {} pub extern "C" fn link_me_please() {}
#[inline(always)] #[inline(always)]
#[allow(clippy::blocks_in_conditions)]
async fn post_to_flutter(response: AFPluginEventResponse, port: i64) { async fn post_to_flutter(response: AFPluginEventResponse, port: i64) {
let isolate = allo_isolate::Isolate::new(port); let isolate = allo_isolate::Isolate::new(port);
if let Ok(_) = isolate match isolate
.catch_unwind(async { .catch_unwind(async {
let ffi_resp = FFIResponse::from(response); let ffi_resp = FFIResponse::from(response);
ffi_resp.into_bytes().unwrap().to_vec() ffi_resp.into_bytes().unwrap().to_vec()
}) })
.await .await
{ {
Ok(_) => {
#[cfg(feature = "sync_verbose_log")] #[cfg(feature = "sync_verbose_log")]
trace!("[FFI]: Post data to dart success"); trace!("[FFI]: Post data to dart success");
} else { },
error!("[FFI]: allo_isolate post panic"); Err(err) => {
error!("[FFI]: allo_isolate post failed: {:?}", err);
},
} }
} }

View File

@ -68,6 +68,7 @@ impl EventIntegrationTest {
authenticator, authenticator,
notification_sender, notification_sender,
cleaner: Arc::new(Cleaner::new(PathBuf::from(clean_path))), cleaner: Arc::new(Cleaner::new(PathBuf::from(clean_path))),
#[allow(clippy::arc_with_non_send_sync)]
local_set: Arc::new(Default::default()), local_set: Arc::new(Default::default()),
} }
} }

View File

@ -261,6 +261,7 @@ impl AppFlowyCore {
error!("Init user failed: {}", err) error!("Init user failed: {}", err)
} }
} }
#[allow(clippy::arc_with_non_send_sync)]
let event_dispatcher = Arc::new(AFPluginDispatcher::new( let event_dispatcher = Arc::new(AFPluginDispatcher::new(
runtime, runtime,
make_plugins( make_plugins(

View File

@ -29,6 +29,7 @@ pub(crate) fn plugin_map_or_crash(plugins: Vec<AFPlugin>) -> AFPluginMap {
let mut plugin_map: HashMap<AFPluginEvent, Arc<AFPlugin>> = HashMap::new(); let mut plugin_map: HashMap<AFPluginEvent, Arc<AFPlugin>> = HashMap::new();
plugins.into_iter().for_each(|m| { plugins.into_iter().for_each(|m| {
let events = m.events(); let events = m.events();
#[allow(clippy::arc_with_non_send_sync)]
let plugins = Arc::new(m); let plugins = Arc::new(m);
events.into_iter().for_each(|e| { events.into_iter().for_each(|e| {
if plugin_map.contains_key(&e) { if plugin_map.contains_key(&e) {
@ -38,6 +39,7 @@ pub(crate) fn plugin_map_or_crash(plugins: Vec<AFPlugin>) -> AFPluginMap {
plugin_map.insert(e, plugins.clone()); plugin_map.insert(e, plugins.clone());
}); });
}); });
#[allow(clippy::arc_with_non_send_sync)]
Arc::new(plugin_map) Arc::new(plugin_map)
} }
@ -75,6 +77,7 @@ impl std::default::Default for AFPlugin {
Self { Self {
name: "".to_owned(), name: "".to_owned(),
states: Default::default(), states: Default::default(),
#[allow(clippy::arc_with_non_send_sync)]
event_service_factory: Arc::new(HashMap::new()), event_service_factory: Arc::new(HashMap::new()),
} }
} }

View File

@ -11,6 +11,7 @@ pub async fn hello() -> String {
async fn test() { async fn test() {
let event = "1"; let event = "1";
let runtime = Arc::new(AFPluginRuntime::new().unwrap()); let runtime = Arc::new(AFPluginRuntime::new().unwrap());
#[allow(clippy::arc_with_non_send_sync)]
let dispatch = Arc::new(AFPluginDispatcher::new( let dispatch = Arc::new(AFPluginDispatcher::new(
runtime, runtime,
vec![AFPlugin::new().event(event, hello)], vec![AFPlugin::new().event(event, hello)],