Change default argument in sink and derived #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To be faster in mutating the state.
Currently, starting Sink and deriving value from the state are running never dispatching as default.
that means the commit operations have to wait for it until all of the updating value finished.
As an original strategy, I decided to use such as this current behavior to achieve an easier way to debug because we can see all of stack-trace with running synchronously.
However, in most cases in the real world, it is not necessary from my current view.
Basically new value from subscribing like
sink
except creating Derive object. (Derive object requires the first value synchronously in init.)So, This PR offers us to use DispatchQueue with asynchronously to receive a new value.
There are differences in Sink and making Derived.
Sink uses
.asyncMain
: it always dispatches to main-queue to deliver new value to the closure.Derived object uses
.asyncSerialBackground
: it always dispatches to the background serial queue to derive new value.In according, commit operation becomes no needs to wait for finishing updating values for each subscriber.
If you need to receive a new value synchronously, you can specify
.passthrough
like our unit testing code.