@@ -232,7 +232,22 @@ where
232232 where
233233 F : Fn ( ) -> TMessage + Send + ' static ,
234234 {
235- send_interval :: < TMessage , F > ( period, self . get_cell ( ) , msg)
235+ // IMPORTANT: See notes on `send_interval` above for important implementation
236+ // notes
237+ let self_clone = self . clone ( ) ;
238+ crate :: concurrency:: spawn ( async move {
239+ let mut timer = crate :: concurrency:: interval ( period) ;
240+ // timer tick's immediately the first time
241+ timer. tick ( ) . await ;
242+ while ACTIVE_STATES . contains ( & self_clone. get_status ( ) ) {
243+ timer. tick ( ) . await ;
244+ // if we receive an error trying to send, the channel is closed and we should stop trying
245+ // actor died
246+ if self_clone. send_message ( msg ( ) ) . is_err ( ) {
247+ break ;
248+ }
249+ }
250+ } )
236251 }
237252
238253 /// Alias of [send_after]
@@ -244,7 +259,12 @@ where
244259 where
245260 F : FnOnce ( ) -> TMessage + Send + ' static ,
246261 {
247- send_after :: < TMessage , F > ( period, self . get_cell ( ) , msg)
262+ let self_clone = self . clone ( ) ;
263+ crate :: concurrency:: spawn ( async move {
264+ crate :: concurrency:: sleep ( period) . await ;
265+ let msg = msg ( ) ;
266+ self_clone. send_message ( msg)
267+ } )
248268 }
249269
250270 /// Alias of [exit_after]
0 commit comments