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
/// Spawns the given actor into the tokio runtime, returning an [`Address`](crate::Address) to it.
#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub fn spawn_tokio<A>(
    actor: A,
    (address, mailbox): (crate::Address<A>, crate::Mailbox<A>),
) -> crate::Address<A>
where
    A: crate::Actor<Stop = ()>,
{
    tokio::spawn(crate::run(mailbox, actor));

    address
}

/// Spawns the given actor into the async_std runtime, returning an [`Address`](crate::Address) to it.
#[cfg(feature = "async_std")]
#[cfg_attr(docsrs, doc(cfg(feature = "async_std")))]
pub fn spawn_async_std<A>(
    actor: A,
    (address, mailbox): (crate::Address<A>, crate::Mailbox<A>),
) -> crate::Address<A>
where
    A: crate::Actor<Stop = ()>,
{
    async_std::task::spawn(crate::run(mailbox, actor));

    address
}

/// Spawns the given actor into the smol runtime, returning an [`Address`](crate::Address) to it.
#[cfg(feature = "smol")]
#[cfg_attr(docsrs, doc(cfg(feature = "smol")))]
pub fn spawn_smol<A>(
    actor: A,
    (address, mailbox): (crate::Address<A>, crate::Mailbox<A>),
) -> crate::Address<A>
where
    A: crate::Actor<Stop = ()>,
{
    smol::spawn(crate::run(mailbox, actor)).detach();

    address
}

/// Spawns the given actor onto the thread-local runtime via `wasm_bindgen_futures`, returning an [`Address`](crate::Address) to it.
#[cfg(feature = "wasm_bindgen")]
#[cfg_attr(docsrs, doc(cfg(feature = "wasm_bindgen")))]
pub fn spawn_wasm_bindgen<A>(
    actor: A,
    (address, mailbox): (crate::Address<A>, crate::Mailbox<A>),
) -> crate::Address<A>
where
    A: crate::Actor<Stop = ()>,
{
    wasm_bindgen_futures::spawn_local(crate::run(mailbox, actor));

    address
}