static TargetEntry Locate2(TTarget o) { var id = _generator.HasId(o, out var firstTime); Asr.IsFalse(firstTime); return(_Registry[id]); }
public void Dispose() { if (Disposed) { return; } if (Disposing) { // Asr.Fail("Self-looping dispose call"); return; } Disposing = true; Action cur = null; while (TryDequeue(ref cur)) { Asr.IsFalse(Disposed); cur.Invoke(); } _stack.Clear(); _stack = null; Disposed = true; }
static TEvents Locate(TTarget o) { var id = _generator.HasId(o, out var firstTime); Asr.IsFalse(firstTime); return(_eventRegistry[id]); }
public static (IPublish pub, ISubscribe sub) PubSub(this IScope scope) { Asr.IsFalse(scope.Disposing); var subject = new Subject(scope); return(subject, subject); }
public static bool TryLocate(TTarget key, out TEvents value) { var id = _generator.HasId(key, out var firstTime); Asr.IsFalse(firstTime); return(_eventRegistry.TryGetValue(id, out value)); }
public void MultipleDispose() { var visited = false; Sample(); Assert.IsTrue(visited); var dispose1 = React.Scope(out var scope1); var r = Outer(scope1); dispose1.Dispose(); Asr.IsTrue(r.GetAwaiter().IsCompleted); async Routine Outer(IScope scope) { var res = await Sample().DisposeOn(scope); Asr.IsFalse(res.HasValue); } async Routine <int> Sample() { visited = true; await _Never.Instance; return(42); } }
public static void Deregister(TTarget target) { var hash = _generator.GetId(target, out var firstTime); Asr.IsFalse(firstTime); if (_Registry.TryGetValue(hash, out var t)) { _Registry[hash].Deregistered = true; } else { Asr.Fail("No such key"); } }
public static void Deregister(TTarget target) { var hash = _generator.GetId(target, out var firstTime); Asr.IsFalse(firstTime); if (_eventRegistry.TryGetValue(hash, out var t)) { t.OnDeregister?.Invoke(); } else { Asr.Fail("No such key"); } _eventRegistry.Remove(hash); }
public Subject(IScope scope) { Asr.IsFalse(scope.Disposed); _current = new LinkedList <Action>(); _next = new LinkedList <Action>(); scope.Subscribe(Dispose); void Dispose() { if (CheckSetTrue(ref _completed)) { return; } _current.Clear(); _next.Clear(); } }
public void Subscribe(Action callback, IScope scope) { if (_completed) { Asr.Fail("Tried to subscribe to ISub which is completed"); return; } Asr.IsFalse(scope.Disposed); var node = _next.AddLast(callback); scope.Subscribe(Remove); void Remove() { node.List?.Remove(node); } }