예제 #1
0
        static TargetEntry Locate2(TTarget o)
        {
            var id = _generator.HasId(o, out var firstTime);

            Asr.IsFalse(firstTime);
            return(_Registry[id]);
        }
예제 #2
0
        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;
        }
예제 #3
0
        static TEvents Locate(TTarget o)
        {
            var id = _generator.HasId(o, out var firstTime);

            Asr.IsFalse(firstTime);
            return(_eventRegistry[id]);
        }
예제 #4
0
파일: React.cs 프로젝트: korchoon/routines
        public static (IPublish pub, ISubscribe sub) PubSub(this IScope scope)
        {
            Asr.IsFalse(scope.Disposing);
            var subject = new Subject(scope);

            return(subject, subject);
        }
예제 #5
0
        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));
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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");
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
        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();
            }
        }
예제 #10
0
        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);
            }
        }