UniRx
UniRx copied to clipboard
await on IMessageBroker.Receive<T> ?
in MonoBehaviour 1 I have a call:
await messageBroker.Receive<Message>();
Debug.Log("Received");
while in the other I have:
messageBroker.Publish<Message>();
Debug.Log("Published");
my problem is that program seems to stop at await stage, no "Publish" or "Received" is printed.
publishing an event is definately happening after await instruction
It seems that it happens with Subject also meaning awaiting it never continues even the OnNext was called on it elsewhere
I understand the problem now. 'await' on Observable waits for the last result before completion, not the first one. The solution is to add FirstAsync() operator to the Rx library and await call like so
await messageBroker.Receive<Message>().FirstAsync();
Yes, Rx's standard await is last. FirstAsync or convert to the UniTask, may works fine.
Yes, Rx's standard await is last. FirstAsync or convert to the UniTask, may works fine.
I found out that await someSubject.ToUniTask();
works like a charm.
But await MessageBroker.Default.Receive<SomeMessage>().ToUniTask()
doesn't.
@neuecc Can u help me here and bring some light on it?
Yes, Rx's standard await is last. FirstAsync or convert to the UniTask, may works fine.
I found out that
await someSubject.ToUniTask();
works like a charm. Butawait MessageBroker.Default.Receive<SomeMessage>().ToUniTask()
doesn't. @neuecc Can u help me here and bring some light on it?
ToUniTask() takes bool parameter of whether it should be awaiting First of last element for IObservable().
await MessageBroker.Default.Receive<SomeMessage>().Take(1).ToUniTask()
WORKS!
await MessageBroker.Default.Receive<SomeMessage>().Take(1).ToUniTask()
WORKS!
Yes, and is effectively the same as Receive().First().ToUniTask()