channels and tokio::spawn
This commit is contained in:
parent
bf8a1ad8ed
commit
0acce0cd46
1 changed files with 183 additions and 9 deletions
|
|
@ -1,12 +1,15 @@
|
|||
use std::{future::Future, pin::Pin};
|
||||
use std::{future::Future, pin::Pin, time::Duration};
|
||||
|
||||
pub async fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
use tokio::sync::oneshot::Receiver;
|
||||
|
||||
|
||||
pub async fn add(left: u64, right: u64, under: Receiver<u64>) -> u64 {
|
||||
left + right + under.await.unwrap()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn add_wrapper(left: u64, right: u64) -> Pin<Box<dyn Future<Output = u64>>> {
|
||||
Box::pin(add(left,right))
|
||||
pub fn add_wrapper(left: u64, right: u64, under: Receiver<u64>) -> Pin<Box<dyn Future<Output = u64> + Send >> {
|
||||
Box::pin(add(left,right, under))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue