Exemplo n.º 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);
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 3
0
 internal void RemoveBinding(Binding.Token bindingToken)
 {
     lock (bindings)
     {
         bindings.Remove(bindingToken);
     }
 }
Exemplo n.º 4
0
 internal void AddBinding(Binding.Token bindingToken)
 {
     lock (bindings)
     {
         bindings.Add(bindingToken);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public void Unbind(Binding.Token bindingToken)
        {
            var flow = Flow;

            if (ReferenceEquals(flow, null))
            {
                return;
            }
            flow.Unsubscribe(bindingToken);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 9
0
 internal void UnsubscribeInternal(Binding.Token token)
 {
     binding.UnbindInternal(token);
 }
Exemplo n.º 10
0
 public void Unsubscribe(Binding.Token token)
 {
     binding.Unbind(token);
 }
Exemplo n.º 11
0
 public void Subscribe(Binding.Token token)
 {
     binding.Bind(token);
 }
Exemplo n.º 12
0
 public static void Unbind(Binding.Token bindingToken)
 {
     currentFlow.Unsubscribe(bindingToken);
 }