Пример #1
0
        protected WaitForAnyEvent(Coroutine coroutine, Event[] requests,
                                  double seconds, params Event[] e)
        {
            this.coroutine = coroutine;

            if (!ReferenceEquals(requests, null))
            {
                waitHandle = WaitHandlePool.Acquire();
                for (int i = 0, count = requests.Length; i < count; ++i)
                {
                    requests[i]._WaitHandle = waitHandle;
                }
                for (int i = 0, count = e.Length; i < count; ++i)
                {
                    e[i]._WaitHandle = waitHandle;
                }
            }

            expected = e;

            handlerTokens = new Binding.Token[expected.Length];
            for (int i = 0; i < expected.Length; ++i)
            {
                handlerTokens[i] = Flow.Bind(expected[i], OnEvent);
            }

            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent {
                    Key = this
                };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken   = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
Пример #2
0
        void OnEvent(Event e)
        {
            for (int i = 0; i < expected.Length; ++i)
            {
                if (actual[i] == null && expected[i].Equivalent(e))
                {
                    Flow.Unbind(handlerTokens[i]);
                    handlerTokens[i] = new Binding.Token();
                    actual[i]        = e;
                    ++count;
                    break;
                }
            }

            if (count >= expected.Length)
            {
                if (timerToken.HasValue)
                {
                    TimeFlow.Default.Cancel(timerToken.Value);
                    Flow.Unbind(timeoutToken);
                }

                if (waitHandle != 0)
                {
                    WaitHandlePool.Release(waitHandle);
                }

                coroutine.Result = actual;
                coroutine.Continue();
            }
        }
Пример #3
0
 internal void RemoveBinding(Binding.Token bindingToken)
 {
     lock (bindings)
     {
         bindings.Remove(bindingToken);
     }
 }
Пример #4
0
 internal void AddBinding(Binding.Token bindingToken)
 {
     lock (bindings)
     {
         bindings.Add(bindingToken);
     }
 }
Пример #5
0
        public WaitForSeconds(Coroutine coroutine, double seconds)
        {
            this.coroutine = coroutine;
            TimeoutEvent e = new TimeoutEvent {
                Key = this
            };

            token = Flow.Bind(e, OnTimeout);
            TimeFlow.Default.Reserve(e, seconds);
        }
Пример #6
0
        public void Unbind(Binding.Token bindingToken)
        {
            var flow = Flow;

            if (ReferenceEquals(flow, null))
            {
                return;
            }
            flow.Unsubscribe(bindingToken);
        }
Пример #7
0
        public WaitForNext(Coroutine coroutine, object result)
        {
            this.coroutine = coroutine;
            this.result    = result;
            TimeoutEvent e = new TimeoutEvent {
                Key = this
            };

            token = Flow.Bind(e, OnTimeout);
            Hub.Post(e);
        }
Пример #8
0
        protected WaitForEvent(Coroutine coroutine, Event request, Event e, double seconds)
        {
            this.coroutine = coroutine;

            if (!ReferenceEquals(request, null))
            {
                int waitHandle = WaitHandlePool.Acquire();
                request._WaitHandle = waitHandle;
                e._WaitHandle       = waitHandle;
            }

            handlerToken = Flow.Bind(e, OnEvent);
            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent {
                    Key = this
                };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken   = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
Пример #9
0
 internal void UnsubscribeInternal(Binding.Token token)
 {
     binding.UnbindInternal(token);
 }
Пример #10
0
 public void Unsubscribe(Binding.Token token)
 {
     binding.Unbind(token);
 }
Пример #11
0
 public void Subscribe(Binding.Token token)
 {
     binding.Bind(token);
 }
Пример #12
0
 public static void Unbind(Binding.Token bindingToken)
 {
     currentFlow.Unsubscribe(bindingToken);
 }