Пример #1
0
        public static IDisposable ListenWhile <T>(this IEventReader <T> reader, ICell <bool> listenCondition, Action <T> act)
        {
            var disp = new DoubleDisposable();

            disp.first = listenCondition.Bind(val =>
            {
                if (val)
                {
                    if (disp.disposed)
                    {
                        return;
                    }
                    if (disp.second != null)
                    {
                        throw new ZergRushException();
                    }
                    disp.second = reader.Subscribe(act);
                }
                else if (disp.second != null)
                {
                    disp.second.Dispose();
                    disp.second = null;
                }
            });
            return(disp);
        }
Пример #2
0
 public void InitializeSubscriptions()
 {
     bus.Subscribe((MatchingMessageReceived @event) =>
     {
         logger.LogInformation("Found matching message with Id={id} at {instant:s}", @event.MessageId, DateTime.UtcNow);
     });
 }
        public void InitializeSubscriptions()
        {
            var matchesCounter = 0;

            bus.Subscribe((MatchingMessageReceived @event) =>
            {
                matchesCounter += 1;
                logger.LogInformation("Found matching message {matchesCounter} times", matchesCounter);
            });
        }
Пример #4
0
        public static async Task SingleMessageAsync(this IEventReader reader)
        {
            bool finished = false;
            var  waiting  = reader.Subscribe(() => { finished = true; });

            while (!finished)
            {
                await frame;
            }
        }
Пример #5
0
        public static CellOfSin SignalSin(this IEventReader e, float scale, float speed, float resetVal, Action <IDisposable> connectionSink)
        {
            CellOfSin cell = new CellOfSin {
                scale = scale, speed = speed
            };

            connectionSink(UnityExecutor.instance.AddUpdatable(cell));
            connectionSink(e.Subscribe(() => cell.Reset(resetVal)));
            return(cell);
        }
Пример #6
0
        // On each event it makes |\____|\_______|\_____....
        public static ICell <float> SignalTrigger(this IEventReader e, float decayTime, Action <IDisposable> connectionSink)
        {
            TriggerCell cell = new TriggerCell {
                decay = decayTime
            };

            connectionSink(UnityExecutor.instance.AddUpdatable(cell));
            connectionSink(e.Subscribe(cell.Reset));
            return(cell);
        }
Пример #7
0
        public static async Task <T> SingleMessageAsync <T>(this IEventReader <T> reader)
        {
            T    result   = default(T);
            bool finished = false;
            var  waiting  = reader.Subscribe(res => { result = res; finished = true; });

            while (!finished)
            {
                await frame;
            }
            return(result);
        }
Пример #8
0
 public static IEventReader Once(this IEventReader reader)
 {
     return(new AnonymousEventReader((Action reaction) =>
     {
         var disp = new SingleDisposable();
         disp.Disposable = reader.Subscribe(() =>
         {
             reaction();
             disp.Dispose();
         });
         return disp;
     }));
 }
Пример #9
0
        // On each event it makes /--\____/--\________....
        public static ICell <float> SignalSpike(this IEventReader e, float attack, float plato, float decay, Action <IDisposable> connectionSink)
        {
            SpikeCell cell = new SpikeCell
            {
                attackPoint = attack,
                platoPoint  = attack + plato,
                decayPoint  = attack + plato + decay
            };

            connectionSink(UnityExecutor.instance.AddUpdatable(cell));
            connectionSink(e.Subscribe(cell.Reset));
            return(cell);
        }
Пример #10
0
 public static IEventReader <T> Filter <T>(this IEventReader <T> eventReader, Func <T, bool> filter)
 {
     return(new AnonymousEventReader <T>(reaction =>
     {
         return eventReader.Subscribe(val =>
         {
             if (filter(val))
             {
                 reaction(val);
             }
         });
     }));
 }
Пример #11
0
 // Result stream is called only once, then the connection is disposed.
 public static IEventReader <T> Once <T>(this IEventReader <T> eventReader)
 {
     return(new AnonymousEventReader <T>((Action <T> reaction) =>
     {
         var disp = new SingleDisposable();
         disp.Disposable = eventReader.Subscribe(val =>
         {
             reaction(val);
             disp.Dispose();
         });
         return disp;
     }));
 }
Пример #12
0
 public static IEventReader WhenTrue(this IEventReader <bool> reader)
 {
     return(new AnonymousEventReader(reaction =>
     {
         return reader.Subscribe(v =>
         {
             if (v)
             {
                 reaction();
             }
         });
     }));
 }
Пример #13
0
 public static IEventReader Filter(this IEventReader eventReader, Func <bool> filter)
 {
     return(new AnonymousEventReader(reaction =>
     {
         return eventReader.Subscribe(() =>
         {
             if (filter())
             {
                 reaction();
             }
         });
     }));
 }
Пример #14
0
 public WaitForEvent(IEventReader reader, float timeout = -1)
 {
     this.timeout = timeout;
     connection   = reader.Subscribe(() =>
     {
         connection.DisconnectSafe();
         ready      = true;
         connection = null;
     });
     if (ready)
     {
         connection.Dispose();
     }
 }
Пример #15
0
        public static IEventReader MergeWith(this IEventReader reader, params IEventReader[] others)
        {
            if (reader == null || others == null || others.Any(s => s == null))
            {
                throw new ArgumentException("Null streams in merge");
            }
            return(new AnonymousEventReader(reaction =>
            {
                var disp = new Connections(others.Length + 1);
                disp.Add(reader.Subscribe(reaction));
                foreach (var other in others)
                {
                    disp.Add(other.Subscribe(reaction));
                }

                return disp;
            }));
        }
Пример #16
0
 public static void Subscribe(this IEventReader e, IConnectionSink connectionSink, Action action)
 {
     connectionSink.AddConnection(e.Subscribe(action));
 }
Пример #17
0
 // Transforms stream value with a function.
 public static IEventReader <T2> Map <T2>(this IEventReader eventReader, Func <T2> map)
 {
     return(new AnonymousEventReader <T2>(reaction => { return eventReader.Subscribe(() => reaction(map())); }));
 }