zpp-2022-rust-seastar / seastar-rs

Idiomatic Rust bindings to the Seastar framework
6 stars 3 forks source link

submit_to works without await #38

Closed grzenow4 closed 1 year ago

grzenow4 commented 1 year ago

This PR changes submit_to function signature to

pub fn submit_to<Func, Fut, Ret>(shard_id: u32, func: Func) -> impl Future<Output = Ret>
where
    Func: FnOnce() -> Fut + Send + 'static,
    Fut: Future<Output = Ret> + 'static,
    Ret: Send + 'static,

Now you don't have to call the await to start a function execution. Simple test for this change is added:

#[seastar::test]
async fn test_submit_to_no_await() {
    let (tx, rx) = futures::channel::oneshot::channel::<i32>();
    let _ = submit_to(0, || async {
        tx.send(42).ok();
    });
    assert!(matches!(rx.await.unwrap(), 42));
}

Also small correction: submit_to checks if runtime is running.