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
use FutureExt;
use ;
use ;
use ;
use SendableFuture;
use SendWrapper;
/* ------ Send workarounds ------ */
/// This trait abstracts over the requirements for spawning a task. In native async runtimes, a
/// task might be ran in a different thread, so the future must be `'static + Send`. In WASM, you
/// are always running in a single thread, so spawning a task only requires that the future that
/// the future is `'static`. This concept is used throughout `troupe` to make writing actors in
/// WASM as easy as possible.
/// Because [`async_trait`](async_trait::async_trait) requires that trait futures are [`Send`]*,
/// both the [`ActorState`](crate::ActorState) and [`Scheduler`](crate::Scheduler) must be `Send`.
/// This can be a problem for WASM, so this wrapper provides a uniform interfaces between WASM and
/// non-WASM targets through which a `Send` workaround can be implemented.
///
/// For WASM targets, this wrapper is just [`SendWrapper`]. This is completely safe to use as WASM
/// applications are strictly bound to a single thread, so this wrapper will never panic.
///
/// *`async_trait` allows futures to be `!Send`, this can not easily be done based on the
/// compilation target, and, generally speaking, `!Send` futures are more difficult to work with
/// that `Send` futures.
pub type SendableWrapper<T> = ;
/* ------ General Utils ------ */
/// A wrapper around `wasm-bindgen-future`'s `spawn_local` function, which spawns a future tha
/// will execute in the background.
pub
/// A future that will sleep for a period of time before waking up. Created by the
/// [`sleep_for`] and [`sleep_until`] fuctions.
;
/// Creates an instance of [`Sleep`] that will sleep for at least as long as the given duration.
/// Creates an instance of [`Sleep`] that will sleep at least until the given point in time.