public void Dispose()
 {
     if (0 == Interlocked.Exchange(ref _disposed, 1))
     {
         _asyncAgent.Dispose();
         _stateSubject.OnCompleted();
         _stateSubject.Dispose();
     }
 }
Exemple #2
0
        public async Task AgentDoesNotHandleMessagesAfterDispose()
        {
            var tcs   = new TaskCompletionSource <int>();
            var agent = new AsyncAgent <int, int>(
                initialState: 0,
                messageHandler: async(state, msg, ct) =>
            {
                await Task.Delay(0, ct);
                tcs.SetResult(msg);
                return(state);
            },
                errorHandler: (ex, ct) => Task.FromResult(true));

            agent.Dispose();
            agent.Send(1);
            await Task.Delay(50);

            Assert.False(tcs.Task.IsCompleted);
        }