@@ -3,7 +3,7 @@ pub use reactor_actor::setup_shared_logger_ref;
33use bincode:: { Decode , Encode } ;
44
55use reactor_actor:: codec:: BincodeCodec ;
6- use reactor_actor:: { BehaviourBuilder , RouteTo , RuntimeCtx } ;
6+ use reactor_actor:: { BehaviourBuilder , RouteTo , RuntimeCtx , actor } ;
77use reactor_macros:: { DefaultPrio , Msg as DeriveMsg } ;
88use std:: collections:: HashMap ;
99use std:: time:: Duration ;
@@ -77,27 +77,25 @@ impl Sender {
7777// ACTORS
7878// //////////////////////////////////////////////////////////////////////////////
7979
80- pub async fn actor ( ctx : RuntimeCtx , other_addr : String ) {
81- BehaviourBuilder :: new ( Processor { } , BincodeCodec :: default ( ) )
82- . send ( Sender :: new ( other_addr) )
83- . generator_if ( ctx. addr == "pinger" , || vec ! [ PingPongMsg :: Ping ] . into_iter ( ) )
84- . build ( )
85- . run ( ctx)
86- . await
87- . unwrap ( ) ;
88- }
89-
9080lazy_static:: lazy_static! {
9181 static ref RUNTIME : tokio:: runtime:: Runtime = tokio:: runtime:: Runtime :: new( ) . unwrap( ) ;
9282}
9383
94- #[ unsafe ( no_mangle ) ]
84+ #[ actor ]
9585pub fn pingpong ( ctx : RuntimeCtx , mut payload : HashMap < String , serde_json:: Value > ) {
96- let other : String = payload
86+ let other_addr : String = payload
9787 . remove ( "other" )
9888 . unwrap ( )
9989 . as_str ( )
10090 . unwrap ( )
10191 . to_string ( ) ;
102- RUNTIME . spawn ( actor ( ctx, other) ) ;
92+ RUNTIME . spawn ( async move {
93+ BehaviourBuilder :: new ( Processor { } , BincodeCodec :: default ( ) )
94+ . send ( Sender :: new ( other_addr) )
95+ . generator_if ( ctx. addr == "pinger" , || vec ! [ PingPongMsg :: Ping ] . into_iter ( ) )
96+ . build ( )
97+ . run ( ctx)
98+ . await
99+ . unwrap ( ) ;
100+ } ) ;
103101}
0 commit comments