@@ -61,12 +61,12 @@ enum Action {
61
61
#[ display( "ListAuthors" ) ]
62
62
ListAuthors {
63
63
#[ debug( "reply" ) ]
64
- reply : flume :: Sender < Result < AuthorId > > ,
64
+ reply : async_channel :: Sender < Result < AuthorId > > ,
65
65
} ,
66
66
#[ display( "ListReplicas" ) ]
67
67
ListReplicas {
68
68
#[ debug( "reply" ) ]
69
- reply : flume :: Sender < Result < ( NamespaceId , CapabilityKind ) > > ,
69
+ reply : async_channel :: Sender < Result < ( NamespaceId , CapabilityKind ) > > ,
70
70
} ,
71
71
#[ display( "ContentHashes" ) ]
72
72
ContentHashes {
@@ -108,12 +108,12 @@ enum ReplicaAction {
108
108
reply : oneshot:: Sender < Result < ( ) > > ,
109
109
} ,
110
110
Subscribe {
111
- sender : flume :: Sender < Event > ,
111
+ sender : async_channel :: Sender < Event > ,
112
112
#[ debug( "reply" ) ]
113
113
reply : oneshot:: Sender < Result < ( ) > > ,
114
114
} ,
115
115
Unsubscribe {
116
- sender : flume :: Sender < Event > ,
116
+ sender : async_channel :: Sender < Event > ,
117
117
#[ debug( "reply" ) ]
118
118
reply : oneshot:: Sender < Result < ( ) > > ,
119
119
} ,
@@ -166,7 +166,7 @@ enum ReplicaAction {
166
166
} ,
167
167
GetMany {
168
168
query : Query ,
169
- reply : flume :: Sender < Result < SignedEntry > > ,
169
+ reply : async_channel :: Sender < Result < SignedEntry > > ,
170
170
} ,
171
171
DropReplica {
172
172
reply : oneshot:: Sender < Result < ( ) > > ,
@@ -222,7 +222,7 @@ struct OpenReplica {
222
222
/// [`SyncHandle::drop`] will not block.
223
223
#[ derive( Debug , Clone ) ]
224
224
pub struct SyncHandle {
225
- tx : flume :: Sender < Action > ,
225
+ tx : async_channel :: Sender < Action > ,
226
226
join_handle : Arc < Option < JoinHandle < ( ) > > > ,
227
227
}
228
228
@@ -232,7 +232,7 @@ pub struct OpenOpts {
232
232
/// Set to true to set sync state to true.
233
233
pub sync : bool ,
234
234
/// Optionally subscribe to replica events.
235
- pub subscribe : Option < flume :: Sender < Event > > ,
235
+ pub subscribe : Option < async_channel :: Sender < Event > > ,
236
236
}
237
237
impl OpenOpts {
238
238
/// Set sync state to true.
@@ -241,7 +241,7 @@ impl OpenOpts {
241
241
self
242
242
}
243
243
/// Subscribe to replica events.
244
- pub fn subscribe ( mut self , subscribe : flume :: Sender < Event > ) -> Self {
244
+ pub fn subscribe ( mut self , subscribe : async_channel :: Sender < Event > ) -> Self {
245
245
self . subscribe = Some ( subscribe) ;
246
246
self
247
247
}
@@ -255,7 +255,7 @@ impl SyncHandle {
255
255
content_status_callback : Option < ContentStatusCallback > ,
256
256
me : String ,
257
257
) -> SyncHandle {
258
- let ( action_tx, action_rx) = flume :: bounded ( ACTION_CAP ) ;
258
+ let ( action_tx, action_rx) = async_channel :: bounded ( ACTION_CAP ) ;
259
259
let actor = Actor {
260
260
store,
261
261
states : Default :: default ( ) ,
@@ -298,7 +298,7 @@ impl SyncHandle {
298
298
pub async fn subscribe (
299
299
& self ,
300
300
namespace : NamespaceId ,
301
- sender : flume :: Sender < Event > ,
301
+ sender : async_channel :: Sender < Event > ,
302
302
) -> Result < ( ) > {
303
303
let ( reply, rx) = oneshot:: channel ( ) ;
304
304
self . send_replica ( namespace, ReplicaAction :: Subscribe { sender, reply } )
@@ -309,7 +309,7 @@ impl SyncHandle {
309
309
pub async fn unsubscribe (
310
310
& self ,
311
311
namespace : NamespaceId ,
312
- sender : flume :: Sender < Event > ,
312
+ sender : async_channel :: Sender < Event > ,
313
313
) -> Result < ( ) > {
314
314
let ( reply, rx) = oneshot:: channel ( ) ;
315
315
self . send_replica ( namespace, ReplicaAction :: Unsubscribe { sender, reply } )
@@ -435,7 +435,7 @@ impl SyncHandle {
435
435
& self ,
436
436
namespace : NamespaceId ,
437
437
query : Query ,
438
- reply : flume :: Sender < Result < SignedEntry > > ,
438
+ reply : async_channel :: Sender < Result < SignedEntry > > ,
439
439
) -> Result < ( ) > {
440
440
let action = ReplicaAction :: GetMany { query, reply } ;
441
441
self . send_replica ( namespace, action) . await ?;
@@ -489,13 +489,13 @@ impl SyncHandle {
489
489
Ok ( store)
490
490
}
491
491
492
- pub async fn list_authors ( & self , reply : flume :: Sender < Result < AuthorId > > ) -> Result < ( ) > {
492
+ pub async fn list_authors ( & self , reply : async_channel :: Sender < Result < AuthorId > > ) -> Result < ( ) > {
493
493
self . send ( Action :: ListAuthors { reply } ) . await
494
494
}
495
495
496
496
pub async fn list_replicas (
497
497
& self ,
498
- reply : flume :: Sender < Result < ( NamespaceId , CapabilityKind ) > > ,
498
+ reply : async_channel :: Sender < Result < ( NamespaceId , CapabilityKind ) > > ,
499
499
) -> Result < ( ) > {
500
500
self . send ( Action :: ListReplicas { reply } ) . await
501
501
}
@@ -566,7 +566,7 @@ impl SyncHandle {
566
566
567
567
async fn send ( & self , action : Action ) -> Result < ( ) > {
568
568
self . tx
569
- . send_async ( action)
569
+ . send ( action)
570
570
. await
571
571
. context ( "sending to iroh_docs actor failed" ) ?;
572
572
Ok ( ( ) )
@@ -581,7 +581,10 @@ impl Drop for SyncHandle {
581
581
fn drop ( & mut self ) {
582
582
// this means we're dropping the last reference
583
583
if let Some ( handle) = Arc :: get_mut ( & mut self . join_handle ) {
584
- self . tx . send ( Action :: Shutdown { reply : None } ) . ok ( ) ;
584
+ // this call is the reason tx can not be a tokio mpsc channel.
585
+ // we have no control about where drop is called, yet tokio send_blocking panics
586
+ // when called from inside a tokio runtime.
587
+ self . tx . send_blocking ( Action :: Shutdown { reply : None } ) . ok ( ) ;
585
588
let handle = handle. take ( ) . expect ( "this can only run once" ) ;
586
589
if let Err ( err) = handle. join ( ) {
587
590
warn ! ( ?err, "Failed to join sync actor" ) ;
@@ -593,7 +596,7 @@ impl Drop for SyncHandle {
593
596
struct Actor {
594
597
store : Store ,
595
598
states : OpenReplicas ,
596
- action_rx : flume :: Receiver < Action > ,
599
+ action_rx : async_channel :: Receiver < Action > ,
597
600
content_status_callback : Option < ContentStatusCallback > ,
598
601
tasks : JoinSet < ( ) > ,
599
602
}
@@ -619,10 +622,10 @@ impl Actor {
619
622
}
620
623
continue ;
621
624
}
622
- action = self . action_rx. recv_async ( ) => {
625
+ action = self . action_rx. recv ( ) => {
623
626
match action {
624
627
Ok ( action) => action,
625
- Err ( flume :: RecvError :: Disconnected ) => {
628
+ Err ( async_channel :: RecvError ) => {
626
629
debug!( "action channel disconnected" ) ;
627
630
break None ;
628
631
}
@@ -979,17 +982,14 @@ impl OpenReplicas {
979
982
}
980
983
981
984
async fn iter_to_channel_async < T : Send + ' static > (
982
- channel : flume :: Sender < Result < T > > ,
985
+ channel : async_channel :: Sender < Result < T > > ,
983
986
iter : Result < impl Iterator < Item = Result < T > > > ,
984
987
) -> Result < ( ) , SendReplyError > {
985
988
match iter {
986
- Err ( err) => channel
987
- . send_async ( Err ( err) )
988
- . await
989
- . map_err ( send_reply_error) ?,
989
+ Err ( err) => channel. send ( Err ( err) ) . await . map_err ( send_reply_error) ?,
990
990
Ok ( iter) => {
991
991
for item in iter {
992
- channel. send_async ( item) . await . map_err ( send_reply_error) ?;
992
+ channel. send ( item) . await . map_err ( send_reply_error) ?;
993
993
}
994
994
}
995
995
}
@@ -1032,10 +1032,10 @@ mod tests {
1032
1032
let id = namespace. id ( ) ;
1033
1033
sync. import_namespace ( namespace. into ( ) ) . await ?;
1034
1034
sync. open ( id, Default :: default ( ) ) . await ?;
1035
- let ( tx, rx) = flume :: bounded ( 10 ) ;
1035
+ let ( tx, rx) = async_channel :: bounded ( 10 ) ;
1036
1036
sync. subscribe ( id, tx) . await ?;
1037
1037
sync. close ( id) . await ?;
1038
- assert ! ( rx. recv_async ( ) . await . is_err( ) ) ;
1038
+ assert ! ( rx. recv ( ) . await . is_err( ) ) ;
1039
1039
Ok ( ( ) )
1040
1040
}
1041
1041
}
0 commit comments