cross-runtime 0.1.0

One task, timer, and runtime surface across native Tokio and browser WebAssembly
Documentation
#![cfg(target_arch = "wasm32")]

use cross_runtime::{spawn_local, timeout};
use futures_channel::oneshot;
use std::time::Duration;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
async fn local_task_joins() {
    assert_eq!(spawn_local(async { 42 }).await.unwrap(), 42);
}

#[wasm_bindgen_test]
async fn dropped_handle_detaches() {
    let (completed, receipt) = oneshot::channel();
    drop(spawn_local(async move {
        let _ = completed.send(42);
    }));
    let value = timeout(Duration::from_secs(1), receipt)
        .await
        .unwrap()
        .unwrap();
    assert_eq!(value, 42);
}

#[wasm_bindgen_test]
async fn abort_cancels() {
    let task = spawn_local(std::future::pending::<()>());
    task.abort();
    assert!(task.await.unwrap_err().is_cancelled());
}

#[wasm_bindgen_test]
async fn timeout_uses_browser_clock() {
    let result = timeout(Duration::from_millis(1), std::future::pending::<()>()).await;
    assert!(result.is_err());
}