Skip to content

Commit

Permalink
Allow the main function to have any return type
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jul 7, 2024
1 parent f415e34 commit 134af24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions rust_crate/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ pub struct DartSignal<T> {
/// the `Runtime` object itself might be moved between threads,
/// along with all the tasks it manages.
#[cfg(not(target_family = "wasm"))]
pub fn start_rust_logic<F>(main_future: F) -> Result<(), RinfError>
pub fn start_rust_logic<F, T>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + Send + 'static,
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
start_rust_logic_real(main_future)
}
Expand All @@ -40,7 +41,7 @@ where
#[cfg(target_family = "wasm")]
pub fn start_rust_logic<F>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + 'static,
F: Future + 'static,
{
start_rust_logic_real(main_future)
}
Expand Down
5 changes: 3 additions & 2 deletions rust_crate/src/interface_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ pub extern "C" fn prepare_isolate_extern(port: i64) {
type ShutdownSenderLock = OnceLock<ThreadLocal<RefCell<Option<ShutdownSender>>>>;
static SHUTDOWN_SENDER: ShutdownSenderLock = OnceLock::new();

pub fn start_rust_logic_real<F>(main_future: F) -> Result<(), RinfError>
pub fn start_rust_logic_real<F, T>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + Send + 'static,
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
// Enable backtrace output for panics.
#[cfg(debug_assertions)]
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<(), RinfError>
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 134af24

Please sign in to comment.