Skip to content

Commit

Permalink
Merge pull request #331 from cunarist/fix-dart-signal
Browse files Browse the repository at this point in the history
Improve performance and stability of Dart signals
  • Loading branch information
temeddix authored May 21, 2024
2 parents e6fd600 + 9ab6ad8 commit 5b8c235
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions flutter_ffi_plugin/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,17 @@ impl ${normalizePascal(messageName)} {
.lock()
.unwrap();
#[cfg(debug_assertions)]
{
{
// After Dart's hot restart,
// there is already a sender that is closed from the previous run.
let pair = cell.take().unwrap();
if pair.0.as_ref().unwrap().is_closed() {
// a sender from the previous run already exists
// which is now closed.
let borrowed = cell.borrow();
let pair = borrowed.as_ref().unwrap();
let is_closed = pair.0.as_ref().unwrap().is_closed();
drop(borrowed);
if is_closed {
let (sender, receiver) = channel(1024);
cell.replace(Some((Some(sender), Some(receiver))));
} else {
cell.replace(Some(pair));
}
}
let pair = cell.take().unwrap();
Expand Down Expand Up @@ -454,20 +456,22 @@ hash_map.insert(
.lock()
.unwrap();
#[cfg(debug_assertions)]
{
{
// After Dart's hot restart,
// there is already a sender that is closed from the previous run.
let pair = cell.take().unwrap();
if pair.0.as_ref().unwrap().is_closed() {
// a sender from the previous run already exists
// which is now closed.
let borrowed = cell.borrow();
let pair = borrowed.as_ref().unwrap();
let is_closed = pair.0.as_ref().unwrap().is_closed();
drop(borrowed);
if is_closed {
let (sender, receiver) = channel(1024);
cell.replace(Some((Some(sender), Some(receiver))));
} else {
cell.replace(Some(pair));
}
}
let borrowed = cell.borrow();
let pair = borrowed.as_ref().unwrap();
let sender = pair.0.clone().unwrap();
let sender = pair.0.as_ref().unwrap();
let _ = sender.try_send(dart_signal);
}),
);
Expand Down

0 comments on commit 5b8c235

Please sign in to comment.