UniTask + R3 subscribe awaiting other subscribers #589
Unanswered
Antoshidza
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to Cysharp projects and I wonder is there a way to subscribe to
Observable<T>
but callback must await any other called callbacks which was invoked before it.I'm in case where for cards game I want to somehow react to the end of turn, one module wants to draw 2 cards every time, but another wants player to select new card as a reward and while both modules execution is async only second one can take more then 1 frame, because asking player to select something on GUI might take undetermined amount of time. I want next modules to await as long as need in such case.
One of the solution would be just implement custom
List<Func<UniTask>>
and do manual subscription, but I really want to keep consistent with UniTask + R3, because whole project uses this query-like R3 syntax like:.Pairwise().Where()...
UPD#0:
I've wrote simple unit test to try some approach I've found here
As I understand the trick here is to convert async callbacks to observables and sequentially
.Concat()
them to original one. But to make it consistent to regular Rx syntax I guess I should implement something likeAwaitObserversSequnceObservable<T> : Observable<T>
which will do.Concat()
inside.Subscribe()
method. Is it a good way to go?UPD#1:
For now I ended up with next solution: I wrap
Observable<T>
in container which holdsUniTask
of last invokedasync UniTask
callback. Client code should just takeAsyncCallbackObservableContainer
and subscribe to it using extensions methods. At least it works and give a possibility to use R3 syntax.From my point of view two weakest parts of it are:
AsyncCallbackObservableContainer<T>
instead of regularObservable<T>
which seems a little inconvenientUniTaskCompletionSource
created to control async callback flow, which I guess is GC problemBeta Was this translation helpful? Give feedback.
All reactions