@@ -161,7 +161,7 @@ private IWampRpcOperation TryGetOperation(long registrationId)
161161
162162 private IWampRawRpcOperationRouterCallback GetCallback ( long requestId )
163163 {
164- return new ServerProxyCallback ( mProxy , requestId ) ;
164+ return new ServerProxyCallback ( mProxy , requestId , this ) ;
165165 }
166166
167167 public void Invocation ( long requestId , long registrationId , InvocationDetails details )
@@ -277,7 +277,6 @@ public void UnregisterError(long requestId, TMessage details, string error, TMes
277277
278278 public void Interrupt ( long requestId , InterruptDetails details )
279279 {
280-
281280 if ( mInvocations . TryRemove ( requestId , out InvocationData invocation ) )
282281 {
283282 invocation . Cancellation . Cancel ( details ) ;
@@ -289,6 +288,17 @@ public void Interrupt(long requestId, InterruptDetails details)
289288 }
290289 }
291290
291+ private void CleanupInvocationData ( long requestId )
292+ {
293+ if ( mInvocations . TryRemove ( requestId , out InvocationData invocation ) )
294+ {
295+ lock ( mLock )
296+ {
297+ mRegistrationsToInvocations . Remove ( invocation . RegistrationId , requestId ) ;
298+ }
299+ }
300+ }
301+
292302 private class RegisterRequest : WampPendingRequest < TMessage , IAsyncDisposable >
293303 {
294304 public RegisterRequest ( IWampRpcOperation operation , IWampFormatter < TMessage > formatter ) :
@@ -342,43 +352,59 @@ private void Cleanup()
342352 private class ServerProxyCallback : IWampRawRpcOperationRouterCallback
343353 {
344354 private readonly IWampServerProxy mProxy ;
355+ private readonly WampCallee < TMessage > mParent ;
345356
346- public ServerProxyCallback ( IWampServerProxy proxy , long requestId )
357+ public ServerProxyCallback ( IWampServerProxy proxy , long requestId , WampCallee < TMessage > parent )
347358 {
348359 mProxy = proxy ;
349360 RequestId = requestId ;
361+ mParent = parent ;
350362 }
351363
352364 public long RequestId { get ; }
353365
366+ private void Cleanup ( YieldOptions yieldOptions = null )
367+ {
368+ if ( yieldOptions ? . Progress != true )
369+ {
370+ mParent . CleanupInvocationData ( RequestId ) ;
371+ }
372+ }
373+
354374 public void Result < TResult > ( IWampFormatter < TResult > formatter , YieldOptions options )
355375 {
356376 mProxy . Yield ( RequestId , options ) ;
377+ Cleanup ( options ) ;
357378 }
358379
359380 public void Result < TResult > ( IWampFormatter < TResult > formatter , YieldOptions options , TResult [ ] arguments )
360381 {
361382 mProxy . Yield ( RequestId , options , arguments . Cast < object > ( ) . ToArray ( ) ) ;
383+ Cleanup ( options ) ;
362384 }
363385
364386 public void Result < TResult > ( IWampFormatter < TResult > formatter , YieldOptions options , TResult [ ] arguments , IDictionary < string , TResult > argumentsKeywords )
365387 {
366388 mProxy . Yield ( RequestId , options , arguments . Cast < object > ( ) . ToArray ( ) , argumentsKeywords . ToDictionary ( x => x . Key , x => ( object ) x . Value ) ) ;
389+ Cleanup ( options ) ;
367390 }
368391
369392 public void Error < TResult > ( IWampFormatter < TResult > formatter , TResult details , string error )
370393 {
371394 mProxy . InvocationError ( RequestId , details , error ) ;
395+ Cleanup ( ) ;
372396 }
373397
374398 public void Error < TResult > ( IWampFormatter < TResult > formatter , TResult details , string error , TResult [ ] arguments )
375399 {
376400 mProxy . InvocationError ( RequestId , details , error , arguments . Cast < object > ( ) . ToArray ( ) ) ;
401+ Cleanup ( ) ;
377402 }
378403
379404 public void Error < TResult > ( IWampFormatter < TResult > formatter , TResult details , string error , TResult [ ] arguments , TResult argumentsKeywords )
380405 {
381406 mProxy . InvocationError ( RequestId , details , error , arguments . Cast < object > ( ) . ToArray ( ) , argumentsKeywords ) ;
407+ Cleanup ( ) ;
382408 }
383409 }
384410
0 commit comments