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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use ;
use Future;
use Pin;
use ;
/// Runs a Rust `Future` on the current thread.
///
/// The `future` must be `'static` because it will be scheduled
/// to run in the background and cannot contain any stack references.
///
/// The `future` will always be run on the next microtask tick even if it
/// immediately returns `Poll::Ready`.
///
/// # Panics
///
/// Note that in wasm panics are currently translated to aborts, but "abort" in
/// this case means that a JavaScript exception is thrown. The wasm module is
/// still usable (likely erroneously) after Rust panics.
///
/// If the `future` provided panics then the returned `Promise` **will not
/// resolve**. Instead it will be a leaked promise. This is an unfortunate
/// limitation of wasm currently that's hoped to be fixed one day!
/// A handle that awaits the result of a [`spawn`]ed future.
///
/// [`spawn`]: fn.spawn.html
// /// Spawn a task that runs when the event loop is idle.
// #[inline]
// pub fn spawn_idle<F, T>(f: F) -> JoinHandle<T>
// where
// F: FnOnce() -> T + 'static,
// T: 'static + Send,
// {
// let (sender, receiver) = channel();
// let f2 = Closure::once(Box::new(move || {
// let t = f();
// let _ = sender.send(t);
// }) as Box<dyn FnOnce()>);
// web_sys::console::time_log();
// let _ = crate::utils::window().request_idle_callback(f2.as_ref().unchecked_ref());
// JoinHandle { receiver }
// }