Пример #1
0
 public static void RunFastBehaviourSubject()
 {
     //FastBehaviourSubject is not really about speed, but also about new parameter less constructor
     //Observers  My Fast Original
     //        0     1923     2878
     //        1     2406     3101
     //        2     3230     3307
     //        3     3113     3508
     //        4     3637     3719
     Console.WriteLine("FastBehaviourSubject");
     Console.WriteLine("Observers  My Fast Original");
     for (var observers = 0; observers < 5; observers++)
     {
         Console.Write("{0,9} ", observers);
         {
             var subj = new FastBehaviourSubject <int>(0);
             for (var i = 0; i < observers; i++)
             {
                 subj.Subscribe(new EmptyIntObserver());
             }
             subj.OnNext(0);
             var sw = Stopwatch.StartNew();
             for (var i = 0; i < 100000000; i++)
             {
                 subj.OnNext(i);
             }
             Console.Write("{0,8} ", sw.ElapsedMilliseconds);
         }
         {
             var subj = new BehaviorSubject <int>(0);
             for (var i = 0; i < observers; i++)
             {
                 subj.Subscribe(new EmptyIntObserver());
             }
             subj.OnNext(0);
             var sw = Stopwatch.StartNew();
             for (var i = 0; i < 100000000; i++)
             {
                 subj.OnNext(i);
             }
             Console.Write("{0,8} ", sw.ElapsedMilliseconds);
         }
         Console.WriteLine();
     }
 }
Пример #2
0
 void ReceiveBody()
 {
     try
     {
         _connector.OnNext(true);
         var buf = new byte[9];
         while (!_disconnected)
         {
             if (!Receive(buf, 0, 1))
             {
                 return;
             }
             var packLen = PackUnpack.LengthVUInt(buf, 0);
             if (packLen > 1)
             {
                 if (!Receive(buf, 1, packLen - 1))
                 {
                     return;
                 }
             }
             int o   = 0;
             var len = PackUnpack.UnpackVUInt(buf, ref o);
             if (len > int.MaxValue)
             {
                 throw new InvalidDataException();
             }
             var result = new byte[len];
             if (len != 0)
             {
                 if (!Receive(result, 0, (int)len))
                 {
                     return;
                 }
             }
             _receiver.OnNext(ByteBuffer.NewAsync(result));
         }
     }
     catch (Exception)
     {
         SignalDisconnected();
     }
     SignalDisconnected();
 }
Пример #3
0
 public void Connect()
 {
     _connector.OnNext(true);
 }