@@ -238,13 +238,13 @@ impl Server {
238
238
subscribe_method_name : String ,
239
239
unsubscribe_method_name : String ,
240
240
) -> Result < RegisteredSubscription , ( ) > {
241
+ log:: debug!( "[register_subscription]: subscribe_method={}, unsubscribe_method={}" , subscribe_method_name, unsubscribe_method_name) ;
241
242
{
242
243
let mut registered_methods = self . registered_methods . lock ( ) ;
243
244
if !registered_methods. insert ( subscribe_method_name. clone ( ) ) {
244
245
return Err ( ( ) ) ;
245
246
}
246
247
if !registered_methods. insert ( unsubscribe_method_name. clone ( ) ) {
247
- registered_methods. remove ( & subscribe_method_name) ;
248
248
return Err ( ( ) ) ;
249
249
}
250
250
}
@@ -253,13 +253,13 @@ impl Server {
253
253
. next_subscription_unique_id
254
254
. fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
255
255
256
- let _ = self
256
+ self
257
257
. to_back
258
258
. unbounded_send ( FrontToBack :: RegisterSubscription {
259
259
unique_id,
260
260
subscribe_method : subscribe_method_name,
261
261
unsubscribe_method : unsubscribe_method_name,
262
- } ) ;
262
+ } ) . map_err ( |_| ( ) ) ? ;
263
263
264
264
Ok ( RegisteredSubscription {
265
265
to_back : self . to_back . clone ( ) ,
@@ -299,11 +299,12 @@ impl RegisteredMethod {
299
299
300
300
impl RegisteredSubscription {
301
301
/// Sends out a value to all the registered clients.
302
+ // TODO: return `Result<(), ()>`
302
303
pub async fn send ( & mut self , value : JsonValue ) {
303
304
let _ = self . to_back . send ( FrontToBack :: SendOutNotif {
304
305
unique_id : self . unique_id ,
305
306
notification : value,
306
- } ) ;
307
+ } ) . await ;
307
308
}
308
309
}
309
310
@@ -314,6 +315,7 @@ impl IncomingRequest {
314
315
}
315
316
316
317
/// Respond to the request.
318
+ // TODO: return `Result<(), ()>`
317
319
pub async fn respond ( mut self , response : impl Into < Result < JsonValue , common:: Error > > ) {
318
320
let _ = self
319
321
. to_back
@@ -381,6 +383,7 @@ async fn background_task(
381
383
subscribe_method,
382
384
unsubscribe_method,
383
385
} ) ) => {
386
+ log:: debug!( "server register subscription=id={:?}, subscribe_method:{}, unsubscribe_method={}" , unique_id, subscribe_method, unsubscribe_method) ;
384
387
debug_assert_ne ! ( subscribe_method, unsubscribe_method) ;
385
388
debug_assert ! ( !subscribe_methods. contains_key( & subscribe_method) ) ;
386
389
debug_assert ! ( !subscribe_methods. contains_key( & unsubscribe_method) ) ;
@@ -399,15 +402,19 @@ async fn background_task(
399
402
unique_id,
400
403
notification,
401
404
} ) ) => {
405
+ log:: debug!( "server send response to subscription={:?}" , unique_id) ;
402
406
debug_assert ! ( subscribed_clients. contains_key( & unique_id) ) ;
403
407
if let Some ( clients) = subscribed_clients. get ( & unique_id) {
408
+ log:: debug!( "{} client(s) is subscribing to {:?}" , clients. len( ) , unique_id) ;
404
409
for client in clients {
405
410
debug_assert_eq ! ( active_subscriptions. get( client) , Some ( & unique_id) ) ;
406
411
debug_assert ! ( server. subscription_by_id( * client) . is_some( ) ) ;
407
412
if let Some ( sub) = server. subscription_by_id ( * client) {
408
413
sub. push ( notification. clone ( ) ) . await ;
409
414
}
410
415
}
416
+ } else {
417
+ log:: warn!( "server subscription: {:?} not found" , unique_id) ;
411
418
}
412
419
}
413
420
Either :: Right ( RawServerEvent :: Notification ( notification) ) => {
0 commit comments