calcite 0.2.6

A library to create deno plugins
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#[calcite::deno_op]
async fn sleep_for(secs: i32) -> Result<String, &'static str> {
    if secs < 0 {
        Err("Number of seconds cannot be negative")
    } else {
        let (tx, rx) = futures::channel::oneshot::channel();
        std::thread::spawn(move || {
            std::thread::sleep(std::time::Duration::from_secs(secs as u64));
            tx.send(()).unwrap();
        });
        rx.await.unwrap();
        Ok(format!("Slept for {} seconds", secs))
    }
}

calcite::export!(sleep_for);