@@ -1358,6 +1358,9 @@ enum ReplyMessage {
13581358 method : String ,
13591359
13601360 sender : oneshot:: Sender < ResponsePayload > ,
1361+
1362+ #[ cfg( feature = "unstable_cancel_request" ) ]
1363+ cancellation_disarm : SentRequestCancellationDisarm ,
13611364 } ,
13621365}
13631366
@@ -1654,6 +1657,9 @@ enum OutgoingMessage {
16541657
16551658 /// where to send the response when it arrives (includes ack channel)
16561659 response_tx : oneshot:: Sender < ResponsePayload > ,
1660+
1661+ #[ cfg( feature = "unstable_cancel_request" ) ]
1662+ cancellation_disarm : SentRequestCancellationDisarm ,
16571663 } ,
16581664
16591665 /// Send a notification to the server.
@@ -2003,6 +2009,8 @@ impl<Counterpart: Role> ConnectionTo<Counterpart> {
20032009 role_id,
20042010 untyped,
20052011 response_tx,
2012+ #[ cfg( feature = "unstable_cancel_request" ) ]
2013+ cancellation_disarm : cancellation. disarm_handle ( ) ,
20062014 } ;
20072015
20082016 match self . message_tx . unbounded_send ( message) {
@@ -2455,6 +2463,8 @@ impl ResponseRouter<serde_json::Value> {
24552463 id : jsonrpcmsg:: Id ,
24562464 role_id : RoleId ,
24572465 sender : oneshot:: Sender < ResponsePayload > ,
2466+ #[ cfg( feature = "unstable_cancel_request" ) ]
2467+ cancellation_disarm : SentRequestCancellationDisarm ,
24582468 ) -> Self {
24592469 let response_method = method. clone ( ) ;
24602470 let response_id = id. clone ( ) ;
@@ -2475,6 +2485,9 @@ impl ResponseRouter<serde_json::Value> {
24752485 id = ?response_id,
24762486 "dropped response because local receiver was gone"
24772487 ) ;
2488+ } else {
2489+ #[ cfg( feature = "unstable_cancel_request" ) ]
2490+ cancellation_disarm. disarm ( ) ;
24782491 }
24792492 Ok ( ( ) )
24802493 } ) ,
@@ -3184,16 +3197,34 @@ fn jsonrpc_id_to_request_id(id: &jsonrpcmsg::Id) -> Result<crate::schema::Reques
31843197}
31853198
31863199#[ cfg( feature = "unstable_cancel_request" ) ]
3187- #[ derive( Clone ) ]
3200+ #[ derive( Clone , Debug ) ]
3201+ pub ( crate ) struct SentRequestCancellationDisarm {
3202+ armed : Arc < AtomicBool > ,
3203+ }
3204+
3205+ #[ cfg( feature = "unstable_cancel_request" ) ]
3206+ impl SentRequestCancellationDisarm {
3207+ fn new ( ) -> Self {
3208+ Self {
3209+ armed : Arc :: new ( AtomicBool :: new ( true ) ) ,
3210+ }
3211+ }
3212+
3213+ fn disarm ( & self ) {
3214+ self . armed . store ( false , Ordering :: Release ) ;
3215+ }
3216+ }
3217+
3218+ #[ cfg( feature = "unstable_cancel_request" ) ]
31883219enum SentRequestCancellation {
31893220 Send {
31903221 message_tx : OutgoingMessageTx ,
31913222 notification : UntypedMessage ,
3192- armed : Arc < AtomicBool > ,
3223+ disarm : SentRequestCancellationDisarm ,
31933224 } ,
31943225 Failed {
31953226 error : String ,
3196- armed : Arc < AtomicBool > ,
3227+ disarm : SentRequestCancellationDisarm ,
31973228 } ,
31983229}
31993230
@@ -3211,25 +3242,25 @@ impl SentRequestCancellation {
32113242 )
32123243 } )
32133244 . map_err ( |error| error. to_string ( ) ) ;
3245+ let disarm = SentRequestCancellationDisarm :: new ( ) ;
32143246
32153247 match notification {
32163248 Ok ( notification) => Self :: Send {
32173249 message_tx,
32183250 notification,
3219- armed : Arc :: new ( AtomicBool :: new ( true ) ) ,
3220- } ,
3221- Err ( error) => Self :: Failed {
3222- error,
3223- armed : Arc :: new ( AtomicBool :: new ( true ) ) ,
3251+ disarm,
32243252 } ,
3253+ Err ( error) => Self :: Failed { error, disarm } ,
32253254 }
32263255 }
32273256
32283257 fn disarm ( & self ) {
3258+ self . disarm_handle ( ) . disarm ( ) ;
3259+ }
3260+
3261+ fn disarm_handle ( & self ) -> SentRequestCancellationDisarm {
32293262 match self {
3230- Self :: Send { armed, .. } | Self :: Failed { armed, .. } => {
3231- armed. store ( false , Ordering :: Release ) ;
3232- }
3263+ Self :: Send { disarm, .. } | Self :: Failed { disarm, .. } => disarm. clone ( ) ,
32333264 }
32343265 }
32353266
@@ -3238,9 +3269,9 @@ impl SentRequestCancellation {
32383269 Self :: Send {
32393270 message_tx,
32403271 notification,
3241- armed ,
3272+ disarm ,
32423273 } => {
3243- if !armed. swap ( false , Ordering :: AcqRel ) {
3274+ if !disarm . armed . swap ( false , Ordering :: AcqRel ) {
32443275 return Ok ( ( ) ) ;
32453276 }
32463277
@@ -3251,8 +3282,8 @@ impl SentRequestCancellation {
32513282 } ,
32523283 )
32533284 }
3254- Self :: Failed { error, armed } => {
3255- if !armed. swap ( false , Ordering :: AcqRel ) {
3285+ Self :: Failed { error, disarm } => {
3286+ if !disarm . armed . swap ( false , Ordering :: AcqRel ) {
32563287 return Ok ( ( ) ) ;
32573288 }
32583289
@@ -3279,17 +3310,17 @@ impl Debug for SentRequestCancellation {
32793310 match self {
32803311 Self :: Send {
32813312 notification,
3282- armed ,
3313+ disarm ,
32833314 ..
32843315 } => f
32853316 . debug_struct ( "SentRequestCancellation" )
32863317 . field ( "notification" , notification)
3287- . field ( "armed" , & armed. load ( Ordering :: Acquire ) )
3318+ . field ( "armed" , & disarm . armed . load ( Ordering :: Acquire ) )
32883319 . finish ( ) ,
3289- Self :: Failed { error, armed } => f
3320+ Self :: Failed { error, disarm } => f
32903321 . debug_struct ( "SentRequestCancellation" )
32913322 . field ( "error" , error)
3292- . field ( "armed" , & armed. load ( Ordering :: Acquire ) )
3323+ . field ( "armed" , & disarm . armed . load ( Ordering :: Acquire ) )
32933324 . finish ( ) ,
32943325 }
32953326 }
0 commit comments