Skip to content

Commit

Permalink
Merge pull request #327 from cunarist/better-dart-signal
Browse files Browse the repository at this point in the history
Improve stability of Dart signals
  • Loading branch information
temeddix authored May 19, 2024
2 parents 06ba57b + 5f3902d commit 80ea848
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions flutter_ffi_plugin/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ impl ${normalizePascal(messageName)} {
#![allow(unused_mut)]
use prost::Message;
use rinf::debug_print;
use rinf::DartSignal;
use std::cell::RefCell;
use std::collections::HashMap;
Expand Down Expand Up @@ -429,11 +430,14 @@ hash_map.insert(
.get_or_init(|| Mutex::new(RefCell::new(None)))
.lock()
.unwrap();
let sender = cell.clone().replace(None).expect(concat!(
"Looks like the channel is not created yet.",
"\\nTry using `$messageName::get_dart_signal_receiver()`."
));
let _ = sender.try_send(dart_signal);
if let Some(sender) = cell.clone().replace(None) {
let _ = sender.try_send(dart_signal);
} else {
debug_print!(concat!(
"Looks like the channel is not created yet.",
"\\nTry using `$messageName::get_dart_signal_receiver()`."
));
}
}),
);
''';
Expand Down

0 comments on commit 80ea848

Please sign in to comment.