1
- use std:: sync:: { Arc , LazyLock } ;
2
- use tokio:: sync:: mpsc:: UnboundedSender ;
3
- use tokio:: sync:: RwLock ;
4
- use tokio:: task:: JoinHandle ;
1
+ use super :: { ActorRunningError , System } ;
5
2
use crate :: actor:: abstract_actor:: { Actor , Handler } ;
6
3
use crate :: actor:: message:: Message ;
7
4
use crate :: actor:: select:: ActorSelect ;
8
5
use crate :: aliases:: ActorName ;
9
6
use crate :: dependency_injection:: Inject ;
10
7
use crate :: system:: builder:: SystemBuilder ;
11
- use super :: { ActorRunningError , System } ;
8
+ use std:: sync:: { Arc , LazyLock } ;
9
+ use tokio:: sync:: mpsc:: UnboundedSender ;
10
+ use tokio:: sync:: RwLock ;
11
+ use tokio:: task:: JoinHandle ;
12
12
13
- static GLOBAL_SYSTEM : LazyLock < Arc < RwLock < System > > > = LazyLock :: new ( || {
14
- Arc :: new ( RwLock :: new ( SystemBuilder :: new_global ( ) . build ( ) ) )
15
- } ) ;
13
+ static GLOBAL_SYSTEM : LazyLock < Arc < RwLock < System > > > =
14
+ LazyLock :: new ( || Arc :: new ( RwLock :: new ( SystemBuilder :: new_global ( ) . build ( ) ) ) ) ;
16
15
17
16
pub struct GlobalSystem { }
18
17
@@ -43,7 +42,9 @@ impl GlobalSystem {
43
42
R : From < ( ActorName , UnboundedSender < M > , A :: State ) > ,
44
43
{
45
44
let mut system = GLOBAL_SYSTEM . write ( ) . await ;
46
- system. register_ref_with_state :: < A , M , R > ( actor_name, state) . await
45
+ system
46
+ . register_ref_with_state :: < A , M , R > ( actor_name, state)
47
+ . await
47
48
}
48
49
49
50
pub async fn spawn_actor < A , S > (
@@ -59,12 +60,20 @@ impl GlobalSystem {
59
60
<A as Actor >:: Inject : Inject + Sized + Send ,
60
61
{
61
62
let mut system = GLOBAL_SYSTEM . write ( ) . await ;
62
- system. spawn_actor :: < A , S > ( actor_name, actor, state, aggregator) . await
63
+ system
64
+ . spawn_actor :: < A , S > ( actor_name, actor, state, aggregator)
65
+ . await
63
66
}
64
67
65
68
pub async fn with ( & mut self , with : impl FnOnce ( & mut System ) ) -> Self {
66
69
let mut system = GLOBAL_SYSTEM . write ( ) . await ;
67
70
with ( & mut system) ;
68
71
GlobalSystem { }
69
72
}
70
- }
73
+
74
+ pub async fn insert_service < T : Send + Sync + ' static > ( & mut self , data : T ) {
75
+ let mut system = GLOBAL_SYSTEM . write ( ) . await ;
76
+ system. insert_service ( data)
77
+ }
78
+ }
79
+
0 commit comments