public IDisposable Subscribe(object obj) { ITemporalObserver <T> observer = (ITemporalObserver <T>)obj; m_observers.TryAdd(observer, 0); return(new Unsubscriber <T>(observer, this)); }
public IDisposable[] AddTemporalObservers <T1, T2, T3>(ITemporalObserver <T1> observer1, ITemporalObserver <T2> observer2, ITemporalObserver <T3> observer3, string[] tokens, string description = null, int priority = TemporalContextManager.NewTokenPriority) { int idx = 0; ITemporalStream stream; stream = m_streams.GetOrAdd(tokens[idx], token => { stream = new TemporalStream <T1>(description); stream.NoObservers += () => { ITemporalStream forNull; m_streams.TryRemove(token, out forNull); }; return(stream); }); TemporalLinker link1 = TemporalLinker.Create((TemporalStream <T1>)stream, observer1); idx++; stream = m_streams.GetOrAdd(tokens[idx], token => { stream = new TemporalStream <T2>(description); stream.NoObservers += () => { ITemporalStream forNull; m_streams.TryRemove(token, out forNull); }; return(stream); }); TemporalLinker link2 = TemporalLinker.Create((TemporalStream <T2>)stream, observer2); idx++; stream = m_streams.GetOrAdd(tokens[idx], token => { stream = new TemporalStream <T3>(description); stream.NoObservers += () => { ITemporalStream forNull; m_streams.TryRemove(token, out forNull); }; return(stream); }); TemporalLinker link3 = TemporalLinker.Create((TemporalStream <T3>)stream, observer3); TemporalLinkedContext ctx = new TemporalLinkedContext(new[] { link1, link2, link3 }, priority); return(new IDisposable[] { ((ITemporalStream)link1.m_stream).Subscribe(new TemporalLinkedContextHelper <T1>(ctx, this, 0)), ((ITemporalStream)link2.m_stream).Subscribe(new TemporalLinkedContextHelper <T2>(ctx, this, 1)), ((ITemporalStream)link3.m_stream).Subscribe(new TemporalLinkedContextHelper <T3>(ctx, this, 2)) }); }
internal void Unssubscribe(ITemporalObserver <T> observer) { int i; m_observers.TryRemove(observer, out i); if (m_observers.Count == 0 && NoObservers != null) { NoObservers(); } }
public TemporalContext(ITemporalValueSource <T> values, ITemporalObserver <T> observer, int priority = TemporalContextManager.IndicatorPriority) { m_values = values; m_observer = observer; m_tokens = new SortedSet <TemporalContextToken>(new TemporalContextTokenComparer()); m_state = 0; m_number = 0; Priority = priority; }
public static TemporalLinker Create <T>(TemporalStream <T> stream, ITemporalObserver <T> observer) { return(new TemporalLinker(stream, observer, stream.TimeFrame, () => observer.Reset(), (time) => { TemporalValue <T> value; if (stream.TryGetValue(time, out value)) { observer.Apply(value); return true; } return false; })); }
public IDisposable Subscribe(object obj) { ITemporalObserver <T> observer = (ITemporalObserver <T>)obj; m_observers.GetOrAdd(observer, _ => { foreach (var v in m_values) { observer.Apply(new TemporalValue <T>(v.Key, v.Value)); } return(0); }); return(new Unsubscriber <T>(observer, this)); }
public IDisposable AddTemporalObserver <T>(ITemporalObserver <T> observer, string token, string description = null, int priority = TemporalContextManager.NewTokenPriority) { ITemporalStream stream = m_streams.GetOrAdd(token, _token => { stream = new TemporalStream <T>(description); stream.NoObservers += () => { ITemporalStream forNull; m_streams.TryRemove(token, out forNull); }; return(stream); }); TemporalContext <T> ctx = new TemporalContext <T>((ITemporalValueSource <T>)stream, observer, priority); return(stream.Subscribe(new TemporalContextHelper <T>(ctx, this))); }
public Unsubscriber(ITemporalObserver <Td> observer, TemporalStream <Td> stream) { m_observer = observer; m_stream = stream; }
public Unsubscriber(ITemporalObserver <Td> observer, TemporalQueue <Td> queue) { m_observer = observer; m_queue = queue; }