protosocket_rpc/server/
spawn.rs1use std::{future::Future, marker::PhantomData};
2
3pub trait Spawn<F>: 'static
8where
9 F: Future + 'static,
10{
11 fn spawn(&mut self, future: F);
13}
14
15#[derive(Debug)]
17pub struct TokioSpawn<F> {
18 _phantom: PhantomData<F>,
19}
20
21impl<F> Default for TokioSpawn<F> {
22 fn default() -> Self {
23 Self {
24 _phantom: Default::default(),
25 }
26 }
27}
28impl<F> Spawn<F> for TokioSpawn<F>
29where
30 F: Future + Send + 'static,
31 F::Output: Send + 'static,
32{
33 fn spawn(&mut self, driver: F) {
34 tokio::spawn(driver);
35 }
36}
37
38#[derive(Debug)]
40pub struct LevelSpawn<F> {
41 _phantom: PhantomData<F>,
42}
43impl<F> Default for LevelSpawn<F> {
44 fn default() -> Self {
45 Self {
46 _phantom: Default::default(),
47 }
48 }
49}
50impl<F> Spawn<F> for LevelSpawn<F>
51where
52 F: Future + Send + 'static,
53 F::Output: Send + 'static,
54{
55 fn spawn(&mut self, future: F) {
56 level_runtime::spawn_local(future);
57 }
58}