public static IDisposable ListenWhile <T>(this IEventStream <T> stream, 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 = stream.Subscribe(act); } else if (disp.second != null) { disp.second.Dispose(); disp.second = null; } }); return(disp); }
public MatrixViewModel(IMatrixRepresentation matrixRepresentation, IEventStream eventStream) { this.matrixRepresentation = matrixRepresentation; this.eventStream = eventStream; eventStream.Subscribe <MatrixSizeChanged>(OnMatrixSizeChanged); }
public static ICell <Vector3> GaussFilter(this ICell <Vector3> value, IEventStream sampler, int samples, IConnectionSink connectionSink, bool prefill = false) { var filter = prefill ? new GaussFilteredVector(samples, value.value) : new GaussFilteredVector(samples); connectionSink.AddConnection(sampler.Subscribe(() => { filter.PushValue(value.value); })); return(filter); }
public ShellViewModel( IMatrixViewModel matrix, IMatrixSettingsViewModel matrixSettings, IEventStream eventStream) { this.Matrix = matrix; this.MatrixSettings = matrixSettings; eventStream.Subscribe <MatrixChanged>(OnMatrixChanged); }
public static async Task SingleMessageAsync(this IEventStream stream) { bool finished = false; var waiting = stream.Subscribe(() => { finished = true; }); while (!finished) { await frame; } }
// On each event it makes |\____|\_______|\_____.... public static ICell <float> SignalTrigger(this IEventStream e, float decayTime, IConnectionSink connectionSink) { TriggerCell cell = new TriggerCell { decay = decayTime }; connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell)); connectionSink.AddConnection(e.Subscribe(cell.Reset)); return(cell); }
public static async Task <T> SingleMessageAsync <T>(this IEventStream <T> stream) { T result = default(T); bool finished = false; var waiting = stream.Subscribe(res => { result = res; finished = true; }); while (!finished) { await frame; } return(result); }
public static IEventStream Once(this IEventStream stream) { return(new AnonymousEventStream((Action reaction) => { var disp = new SingleDisposable(); disp.Disposable = stream.Subscribe(() => { reaction(); disp.Dispose(); }); return disp; })); }
public static ICell <float> DecayingPush(this IEventStream <float> e, float ampPerPush, float asymptote, IConnectionSink sink) { Cell <float> value = new Cell <float>(); sink.AddConnection(e.Subscribe(val => { value.value = Mathf.Atan((value.value + ampPerPush * val) / asymptote) / (Mathf.PI / 4) * asymptote; })); sink.AddConnection( UnityExecutor.Instance.AddUpdatable(new AnonymousUpdatable(dt => { value.value /= 1.1f; }))); return(value); }
// Result stream is called only once, then the connection is disposed. public static IEventStream <T> Once <T>(this IEventStream <T> eventStream) { return(new AnonymousEventStream <T>((Action <T> reaction) => { var disp = new SingleDisposable(); disp.Disposable = eventStream.Subscribe(val => { reaction(val); disp.Dispose(); }); return disp; })); }
public static IEventStream WhenTrue(this IEventStream <bool> stream) { return(new AnonymousEventStream(reaction => { return stream.Subscribe(v => { if (v) { reaction(); } }); })); }
public static IEventStream Filter(this IEventStream eventStream, Func <bool> filter) { return(new AnonymousEventStream(reaction => { return eventStream.Subscribe(() => { if (filter()) { reaction(); } }); })); }
public static IEventStream <T> Filter <T>(this IEventStream <T> eventStream, Func <T, bool> filter) { return(new AnonymousEventStream <T>(reaction => { return eventStream.Subscribe(val => { if (filter(val)) { reaction(val); } }); })); }
public static CellOfSin SignalSin(this IEventStream reset, float scale, float speed, float resetVal, IConnectionSink connectionSink) { CellOfSin cell = new CellOfSin { scale = scale, speed = speed }; connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell)); if (reset != null) { connectionSink.AddConnection(reset.Subscribe(() => cell.Reset(resetVal))); } return(cell); }
// On each event it makes /--\____/--\________.... public static ICell <float> SignalSpike(this IEventStream e, float attack, float plato, float decay, IConnectionSink connectionSink) { SpikeCell cell = new SpikeCell { attackPoint = attack, platoPoint = attack + plato, decayPoint = attack + plato + decay }; connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell)); connectionSink.AddConnection(e.Subscribe(cell.Reset)); return(cell); }
public WaitForEvent(IEventStream stream, float timeout = -1) { this.timeout = timeout; connection = stream.Subscribe(() => { connection.DisconnectSafe(); ready = true; connection = null; }); if (ready) { connection.Dispose(); } }
public static IEventStream MergeWith(this IEventStream stream, params IEventStream[] others) { if (stream == null || others == null || others.Any(s => s == null)) { throw new ArgumentException("Null streams in merge"); } return(new AnonymousEventStream(reaction => { var disp = new Connections(others.Length + 1); disp.Add(stream.Subscribe(reaction)); foreach (var other in others) { disp.Add(other.Subscribe(reaction)); } return disp; })); }
public static void Subscribe <T>(this IEventStream <T> stream, IConnectionSink connectionSink, Action <T> action) { connectionSink.AddConnection(stream.Subscribe(action)); }
public static void Subscribe(this IEventStream e, IConnectionSink connectionSink, Action action) { connectionSink.AddConnection(e.Subscribe(action)); }
// Transforms stream value with a function. public static IEventStream <T2> Map <T2>(this IEventStream eventStream, Func <T2> map) { return(new AnonymousEventStream <T2>(reaction => { return eventStream.Subscribe(() => reaction(map())); })); }