11use crate :: actor_loop;
2- use futures :: FutureExt ;
2+ use futures_lite :: FutureExt ;
33use std:: any:: Any ;
44use std:: cell:: RefCell ;
55use std:: collections:: HashMap ;
66use std:: fmt:: { Debug , Display , Formatter } ;
7+ use std:: future:: Future ;
78use std:: hash:: Hash ;
89use std:: panic:: AssertUnwindSafe ;
910use std:: pin:: Pin ;
@@ -25,7 +26,7 @@ tokio::task_local! {
2526}
2627
2728pub struct JoinHandle < M : MessageSet > {
28- inner : Pin < Box < dyn futures :: Future < Output = ( M :: Meta , ActorStatus ) > + Send > > ,
29+ inner : Pin < Box < dyn Future < Output = ( M :: Meta , ActorStatus ) > + Send > > ,
2930 abort_handle : tokio:: task:: AbortHandle ,
3031}
3132
@@ -41,7 +42,7 @@ impl<M: MessageSet> Drop for JoinHandle<M> {
4142 }
4243}
4344
44- impl < M : MessageSet > futures :: Future for JoinHandle < M > {
45+ impl < M : MessageSet > Future for JoinHandle < M > {
4546 type Output = ( M :: Meta , ActorStatus ) ;
4647
4748 fn poll (
@@ -117,7 +118,7 @@ pub trait Actor<M: MessageSet>: Sized + Send + 'static {
117118 fn run (
118119 & mut self ,
119120 ctx : & mut ActorContext < M > ,
120- ) -> impl futures :: Future < Output = Result < ( ) , ActorError > > + Send {
121+ ) -> impl Future < Output = Result < ( ) , ActorError > > + Send {
121122 async {
122123 actor_loop ! ( self , ctx) ;
123124 Ok ( ( ) )
@@ -128,15 +129,15 @@ pub trait Actor<M: MessageSet>: Sized + Send + 'static {
128129 & mut self ,
129130 _ctx : & mut ActorContext < M > ,
130131 _msg : SystemMsg < M :: ObservableState > ,
131- ) -> impl futures :: Future < Output = ( ) > + Send {
132+ ) -> impl Future < Output = ( ) > + Send {
132133 async move { }
133134 }
134135
135136 fn on_msg (
136137 & mut self ,
137138 _ctx : & mut ActorContext < M > ,
138139 _msg : M :: Msg ,
139- ) -> impl futures :: Future < Output = ( ) > + Send {
140+ ) -> impl Future < Output = ( ) > + Send {
140141 async move { }
141142 }
142143}
@@ -254,40 +255,12 @@ where
254255 let runnable = tracing:: Instrument :: instrument ( runnable, span) ;
255256
256257 let actor_id = handle. meta . clone ( ) ;
257- let fut = runnable. map ( move |status| ( actor_id, status) ) ;
258-
259- ( handle, fut)
260- }
261-
262- pub fn spawn < A , M > ( a : A , config : RunnerConfig ) -> ( ActorHandle < M > , JoinHandle < M > )
263- where
264- M : MessageSet ,
265- A : Actor < M > ,
266- {
267- let ( handle, runnable) = prepare ( a, config) ;
268- let join = tokio:: spawn ( runnable) ;
269- let abort_handle = join. abort_handle ( ) ;
270-
271- let actor_id = handle. meta . clone ( ) ;
272- let join = join
273- . map ( |res| res. unwrap_or ( ( actor_id, ActorStatus :: ShutDown ) ) )
274- . boxed ( ) ;
275-
276- (
277- handle,
278- JoinHandle {
279- inner : join,
280- abort_handle,
281- } ,
282- )
283- }
258+ let runnable = async move {
259+ let status = runnable. await ;
260+ ( actor_id, status)
261+ } ;
284262
285- pub fn spawn_default < A , M > ( a : A ) -> ( ActorHandle < M > , JoinHandle < M > )
286- where
287- M : MessageSet ,
288- A : Actor < M > ,
289- {
290- spawn ( a, RunnerConfig :: default ( ) )
263+ ( handle, runnable)
291264}
292265
293266async fn run < A , M > ( mut a : A , mut ctx : ActorContext < M > ) -> ActorStatus
0 commit comments