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);
            }
        }
        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);
 }