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(); } }
internal void RemoveBinding(Binding.Token bindingToken) { lock (bindings) { bindings.Remove(bindingToken); } }
internal void AddBinding(Binding.Token bindingToken) { lock (bindings) { bindings.Add(bindingToken); } }
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); }
public void Unbind(Binding.Token bindingToken) { var flow = Flow; if (ReferenceEquals(flow, null)) { return; } flow.Unsubscribe(bindingToken); }
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); }
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); } }
internal void UnsubscribeInternal(Binding.Token token) { binding.UnbindInternal(token); }
public void Unsubscribe(Binding.Token token) { binding.Unbind(token); }
public void Subscribe(Binding.Token token) { binding.Bind(token); }
public static void Unbind(Binding.Token bindingToken) { currentFlow.Unsubscribe(bindingToken); }