blob: 0aa32a70b033e4f228b754c9e74fd9fd2f5c6e67 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#![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();
}
|