public async Task Async() { var mb = new AsyncMessageBroker(); var l = new List<string>(); var d1 = mb.Subscribe<int>(async x => l.Add("a:" + x)); var d2 = mb.Subscribe<int>(async x => l.Add("b:" + x)); await mb.PublishAsync(100); l.Is("a:100", "b:100"); l.Clear(); d2.Dispose(); await mb.PublishAsync(200); l.Is("a:200"); l.Clear(); d1.Dispose(); await mb.PublishAsync(300); l.Count.Is(0); }
public void ChangeState(Enum targetState) { if (_running) { Debug.Log("StateMachine: <color=red>Cannot change state while transitioning</color>"); return; } _nextState = targetState; var state = new State <Enum>(); state.Enter = () => { _running = true; _broker.PublishAsync(new Tuple <Enum, bool>(targetState, true)).Subscribe(_ => { _running = false; state.HasEntered.Value = true; _currentState.OnNext(state.Estate); _current = state.Estate; //_history.Add(state.Estate); }).AddTo(state.Disposable); }; state.Exit = () => { _running = true; _broker.PublishAsync(new Tuple <Enum, bool>(targetState, false)).Subscribe(_ => { _running = false; state.HasExited.Value = true; if (!BlendMode) { Next(); } }).AddTo(state.Disposable); }; state.Estate = targetState; _queue.Add(state); Next(); }
public void Publish <T>(T message) { queue.Add(() => { running = true; broker.PublishAsync(message).Subscribe(_ => { running = false; Next(); }); }); Next(); }
public async Task Async() { var mb = new AsyncMessageBroker(); var l = new List <string>(); var d1 = mb.Subscribe <int>(async x => l.Add("a:" + x)); var d2 = mb.Subscribe <int>(async x => l.Add("b:" + x)); await mb.PublishAsync(100); l.Is("a:100", "b:100"); l.Clear(); d2.Dispose(); await mb.PublishAsync(200); l.Is("a:200"); l.Clear(); d1.Dispose(); await mb.PublishAsync(300); l.Count.Is(0); }
public Task PublishAsync <T>(T message) { _messageBroker.Publish(message); return(_asyncMessageBroker.PublishAsync(message).ToTask()); }