The docs say fork is an attached fork and spawn is a detached fork - how do they differ?
标签:
redux-saga
相关问题
- How to reset filter values in react admin framewor
- Access React context value from redux-saga functio
- How to handle multiple interdependent sagas when r
- redux-saga: How to create multiple calls/side-effe
- Redux sagas Fetch only once when same id is dispat
相关文章
- redux-saga: How to create multiple calls/side-effe
- Redux sagas Fetch only once when same id is dispat
- How to provide a history instance to a saga?
- Promises in redux-saga
- How to handle errors in fetch() responses with Red
- MVVM architectural pattern for a ReactJS applicati
- What is the idiomatic way of starting rootSaga?
- redux-saga when to use fork?
In the same docs it says:
Let's say we have this setup where in the middle of execution flow we call
fetchAll()
that might call eitherfork
orspawn
:What we see is, within
call
context the fork isnon-blocking
, butcall
is not going to finish until all its children processes are finalised, sincecall
itself is a blocking effect.You wouldn't see the same if you call a
fork
within anotherfork
, since fork itself is non-blocking, and inner forked processes wouldleak
out of outer fork processes, but will be kept inside the nearest blocking context. This is the essence ofattachment to parent
.So parent
yield call(forkedProcess)
being of a blocking nature will await forreturn
orthrow resolution
of child fork processes.This is not the case with
spawn()
, however, since spawn is detached from enclosing parent process, i.e. attached to the root process, thus localparent
doesn't have to wait.Hope this clarifies it a bit.
One way to look at it is to see your saga's as a Graph. 'fork' creates a child from the calling process. While 'spawn' creates a new child at the root of the graph.
So when you 'fork' another process, the parent process will wait until the 'forked' process is finished. Also every exception will bubble up from the child to the parent and can be caught in the parent.
A 'spawned' process though will not block the parent, so the next 'yield' statement is called immediately. Also the parent process will not be able to catch any exceptions that happen in the 'spawned' process.
I hope this was helpful.