[WIP] Awaitable store with async saga support#62
[WIP] Awaitable store with async saga support#62cmeeren wants to merge 10 commits intoGuillaumeSalles:masterfrom cmeeren:awaitable-store
Conversation
|
@dcolthorp It should be exception safe now. Calling I've added a ton of tests, check them out to see how it's used. Some tests might be unnecessary due to being pretty much being guaranteed by .NET, but much of it was copy-paste and I didn't stop to think too hard on whether all the tests were strictly needed. |
|
I've updated the initial comment with more information. @dcolthorp Regarding #47 (comment) and your mention of |
This is a work in progress. Posting here as a PR so we can discuss. Particularly interested in what @dcolthorp has to say. Regarding #47 (comment), this PR provides a way of registering sagas using an action observable AND awaiting the completion of all actions in the store. See unit tests for details.
Due to necessity I branched this off of my previous branch (PR #60), hence why the commit from that PR also shows up in this PR.
I've just lumped all code together in one file for now.
The distinct features in this PR are:
The following two delegates denoting async/blocking sagas:
void Saga(action, store)Task AsyncSaga(action, store)I'm considering changing this a bit so that they only accept an
actionparameter, and then have the sagas be returned from a function that accepts the store. Kind of like middleware, where the middleware has access to the store through the function that creates the middleware. Removing the store parameter would make the saga register syntax look cleaner, and also removes the store parameter from sagas that don't need it. Input welcome.Two extension methods on
IObservable<T>for registering async and non-async sagas.ObservableActionStorewhich exposes an IObservable of actions. Can be dropped in favor of a simple extension toStoreif we figure out New ActionDispatched event would duplicate StateChanged #63.AwaitableStorewhich exposesDispatchAsyncand also has internally accessible member(s) for keeping track of async operations thatDispatchAsyncshould await (currently this is simply a methodIDisposable AsyncOperation()to be used inusingstatements, as seen in the extension method.)The
IObservable<T>extension methodsRunsSagaandRunsAsyncSagaThings to do before this can be merged: