channels and tokio::spawn

This commit is contained in:
Andy Killorin 2024-12-19 12:37:38 -05:00
commit 0acce0cd46
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -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)]