Пример #1
0
 public IDisposable OnEnter(Enum where, Func <IObservable <Unit> > asyncMessageReceiver)
 {
     _hasSubscribers = true;
     return(_broker.Subscribe <Tuple <Enum, bool> >((sate) =>
     {
         if (sate.Item1.Equals(where) && sate.Item2)
         {
             return asyncMessageReceiver();
         }
         else
         {
             return Observable.ReturnUnit();
         }
     }));
 }
        public async Task Async()
        {
            var mb = new AsyncMessageBroker();
            var l = new List<string>();

            var d1 = mb.Subscribe<int>(async x => l.Add("a:" + x));
            var d2 = mb.Subscribe<int>(async x => l.Add("b:" + x));

            await mb.PublishAsync(100);
            l.Is("a:100", "b:100"); l.Clear();

            d2.Dispose();
            await mb.PublishAsync(200);
            l.Is("a:200"); l.Clear();

            d1.Dispose();
            await mb.PublishAsync(300);
            l.Count.Is(0);
        }
Пример #3
0
    public async Task Async()
    {
        var mb = new AsyncMessageBroker();
        var l  = new List <string>();

        var d1 = mb.Subscribe <int>(async x => l.Add("a:" + x));
        var d2 = mb.Subscribe <int>(async x => l.Add("b:" + x));

        await mb.PublishAsync(100);

        l.Is("a:100", "b:100"); l.Clear();

        d2.Dispose();
        await mb.PublishAsync(200);

        l.Is("a:200"); l.Clear();

        d1.Dispose();
        await mb.PublishAsync(300);

        l.Count.Is(0);
    }
 public IDisposable Subscribe <T>(Func <T, IObservable <Unit> > asyncMessageReceiver)
 {
     return(broker.Subscribe(asyncMessageReceiver));
 }