コード例 #1
0
ファイル: BroadcastSpec.cs プロジェクト: ststeiger/akka.net
 protected override void OnReceive(object message)
 {
     if (message is string)
     {
         var s = (string)message;
         if (s == "end")
         {
             _latch.CountDown();
         }
     }
     if (message is int)
     {
         var i = (int)message;
         _counter.GetAndAdd(i);
     }
 }
コード例 #2
0
            protected override void OnReceive(object message)
            {
                var messageString = message as string;

                if (messageString != null)
                {
                    if (messageString == "end")
                    {
                        _latch.CountDown();
                    }
                }

                if (message is int)
                {
                    var i = (int)message;
                    _counter.GetAndAdd(i);
                }
            }
コード例 #3
0
            public void Subscribe(ISubscriber <int> subscriber)
            => subscriber.OnSubscribe(new LamdaSubscription(onRequest: n =>
            {
                Action signalling = () =>
                {
                    for (var i = 0L; i <= n; i++)
                    {
                        if (_token.IsCancellationRequested)
                        {
                            break;
                        }

                        // one signal too much
                        try
                        {
                            var signal = i;
                            Task.Run(() =>
                            {
                                try
                                {
                                    subscriber.OnNext((int)signal);
                                }
                                catch (Exception ex)
                                {
                                    if (!_swallowOnNextExceptions)
                                    {
                                        throw new Exception("onNext threw an exception!", ex);
                                    }
                                    else
                                    {
                                        // yes, swallow the exception, we're not asserting and they'd just end up being logged (stdout),
                                        // which we do not need in this specific PublisherVerificationTest
                                    }
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            if (ex is Latch.ExpectedOpenLatchException)
                            {
                                if (_concurrentAccessCaused.CompareAndSet(false, true))
                                {
                                    throw new Exception("Concurrent access detected", ex);
                                }
                            }
                            else
                            {
                                if (!_concurrentAccessCaused.Value)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                };

                // must be guarded like this in case a Subscriber triggers request() synchronously from it's onNext()
                while (_startedSignallingThreads.GetAndAdd(1) < MaxSignallingThreads)
                {
                    Task.Run(signalling, _token);
                }
            }));