Skip to content

Commit

Permalink
Ease the return type of the main Rust function
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jun 15, 2024
1 parent 7226d0d commit 4cba370
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rust_crate/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct DartSignal<T> {
#[cfg(not(target_family = "wasm"))]
pub fn start_rust_logic<F>(main_future: F) -> Result<()>
where
F: Future<Output = ()> + Send + 'static,
F: Future + Send + 'static,
{
start_rust_logic_real(main_future)
}
Expand All @@ -39,7 +39,7 @@ where
#[cfg(target_family = "wasm")]
pub fn start_rust_logic<F>(main_future: F) -> Result<()>
where
F: Future<Output = ()> + 'static,
F: Future + 'static,
{
start_rust_logic_real(main_future)
}
Expand Down
6 changes: 4 additions & 2 deletions rust_crate/src/interface_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static TOKIO_RUNTIME: TokioRuntime = OnceLock::new();

pub fn start_rust_logic_real<F>(main_future: F) -> Result<()>
where
F: Future<Output = ()> + Send + 'static,
F: Future + Send + 'static,
{
// Enable backtrace output for panics.
#[cfg(debug_assertions)]
Expand All @@ -52,7 +52,9 @@ where
let tokio_runtime = Builder::new_multi_thread().enable_all().build()?;

// Run the main function.
tokio_runtime.spawn(main_future);
tokio_runtime.spawn(async {
main_future.await;
});
TOKIO_RUNTIME
.get_or_init(|| ThreadLocal::new(|| RefCell::new(None)))
.with(move |cell| {
Expand Down
6 changes: 4 additions & 2 deletions rust_crate/src/interface_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasm_bindgen_futures::spawn_local;

pub fn start_rust_logic_real<F>(main_future: F) -> Result<()>
where
F: Future<Output = ()> + 'static,
F: Future + 'static,
{
// Add kind description for panics.
#[cfg(debug_assertions)]
Expand All @@ -17,7 +17,9 @@ where
}

// Run the main function.
spawn_local(main_future);
spawn_local(async {
main_future.await;
});

Ok(())
}
Expand Down

0 comments on commit 4cba370

Please sign in to comment.