Skip to content

Commit

Permalink
Allow some optimization, export some future types
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad9486 committed Oct 3, 2024
1 parent a4fc405 commit 68626c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions rust_crate/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ impl<T> SignalReceiver<T> {
/// receiver is allowed to receive messages. If there are no messages in the
/// queue, the receiver will wait until a new message is sent. If this receiver
/// is not active, it will return `None`.
pub async fn recv(&self) -> Option<T> {
pub fn recv(&self) -> RecvFuture<T> {
RecvFuture {
inner: self.inner.clone(),
receiver_id: self.id, // Pass the receiver's ID to the future
}
.await
}
}

Expand Down Expand Up @@ -88,7 +87,7 @@ impl<T> Clone for SignalReceiver<T> {
/// A future that represents the attempt of a `SignalReceiver` to receive a
/// message. This future is only completed when the active receiver receives
/// a message from the queue.
struct RecvFuture<T> {
pub struct RecvFuture<T> {
inner: Arc<Mutex<SignalChannel<T>>>,
receiver_id: usize, // Track which receiver is polling
}
Expand Down
4 changes: 2 additions & 2 deletions rust_crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod interface_os;
#[cfg(target_family = "wasm")]
mod interface_web;

pub use channel::{signal_channel, SignalReceiver, SignalSender};
pub use channel::{signal_channel, RecvFuture, SignalReceiver, SignalSender};
pub use error::RinfError;
pub use interface::{send_rust_signal, start_rust_logic, DartSignal};
pub use shutdown::dart_shutdown;
pub use shutdown::{dart_shutdown, EventFuture};
4 changes: 2 additions & 2 deletions rust_crate/src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct ShutdownEvents {
/// Awaiting this receiver in the async main Rust function
/// is necessary to prevent the async runtime in Rust from
/// finishing immediately.
pub async fn dart_shutdown() {
SHUTDOWN_EVENTS.dart_stopped.wait_async().await;
pub fn dart_shutdown() -> EventFuture {
SHUTDOWN_EVENTS.dart_stopped.wait_async()
}

/// Synchronization primitive that allows
Expand Down

0 comments on commit 68626c9

Please sign in to comment.