embassy/examples/wasm/src/lib.rs
Ulf Lilleengen e24528051b Add WASM support for executor
* Adds an executor for WASM runtimes based on wasm_bindgen.
* Add time driver based on JS time handling.
* Add example that can run in browser locally.
* Update to critical-section version that supports 'std' flag
2021-09-13 16:42:39 +02:00

38 lines
1007 B
Rust

#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
use embassy::{
executor::Spawner,
time::{Duration, Timer},
};
#[embassy::task]
async fn ticker() {
let window = web_sys::window().expect("no global `window` exists");
let mut counter = 0;
loop {
let document = window.document().expect("should have a document on window");
let list = document
.get_element_by_id("log")
.expect("should have a log element");
let li = document
.create_element("li")
.expect("error creating list item element");
li.set_text_content(Some(&format!("tick {}", counter)));
list.append_child(&li).expect("error appending list item");
log::info!("tick {}", counter);
counter += 1;
Timer::after(Duration::from_secs(1)).await;
}
}
#[embassy::main]
async fn main(spawner: Spawner) {
wasm_logger::init(wasm_logger::Config::default());
spawner.spawn(ticker()).unwrap();
}