2021-09-13 14:35:40 +02:00
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
|
|
|
use embassy_time::{Duration, Timer};
|
2021-09-13 14:35:40 +02:00
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::task]
|
2021-09-13 14:35:40 +02:00
|
|
|
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");
|
2022-06-12 22:15:44 +02:00
|
|
|
let list = document.get_element_by_id("log").expect("should have a log element");
|
2021-09-13 14:35:40 +02:00
|
|
|
|
2022-06-12 22:15:44 +02:00
|
|
|
let li = document.create_element("li").expect("error creating list item element");
|
2021-09-13 14:35:40 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2021-09-13 14:35:40 +02:00
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
wasm_logger::init(wasm_logger::Config::default());
|
|
|
|
spawner.spawn(ticker()).unwrap();
|
|
|
|
}
|