11use std:: pin:: Pin ;
22
3- use futures:: { StreamExt , stream:: FuturesUnordered } ;
43use pulsebeam_runtime:: { actor, sync:: Arc } ;
4+ use tokio:: task:: JoinSet ;
55
66pub type ShardTask = Pin < Box < dyn futures:: Future < Output = ( ) > + Send > > ;
77
@@ -11,7 +11,7 @@ pub enum ShardMessage {
1111
1212pub struct ShardActor {
1313 shard_id : usize ,
14- tasks : FuturesUnordered < ShardTask > ,
14+ tasks : JoinSet < ( ) > ,
1515}
1616
1717pub struct ShardMessageSet ;
@@ -48,7 +48,7 @@ impl actor::Actor<ShardMessageSet> for ShardActor {
4848 pulsebeam_runtime:: actor_loop!( self , _ctx,
4949 pre_select: { } ,
5050 select: {
51- Some ( _) = self . tasks. next ( ) => {
51+ Some ( _) = self . tasks. join_next ( ) => {
5252 // task completed, shard does nothing else
5353 }
5454 }
@@ -59,7 +59,7 @@ impl actor::Actor<ShardMessageSet> for ShardActor {
5959
6060 async fn on_msg ( & mut self , _ctx : & mut actor:: ActorContext < ShardMessageSet > , msg : ShardMessage ) {
6161 let ShardMessage :: AddTask ( task) = msg;
62- self . tasks . push ( task) ;
62+ self . tasks . spawn ( task) ;
6363 metrics:: counter!( "shard_task_count" , "shard_id" => self . shard_id. to_string( ) )
6464 . absolute ( self . tasks . len ( ) as u64 ) ;
6565 }
@@ -69,7 +69,7 @@ impl ShardActor {
6969 pub fn new ( shard_id : usize ) -> Self {
7070 Self {
7171 shard_id,
72- tasks : FuturesUnordered :: new ( ) ,
72+ tasks : JoinSet :: new ( ) ,
7373 }
7474 }
7575}
0 commit comments