What's the difference between fork and spawn in redux-saga?

前端 未结 2 1908
醉酒成梦
醉酒成梦 2020-12-29 04:06

The docs say fork is an attached fork and spawn is a detached fork - how do they differ?

2条回答
  •  孤独总比滥情好
    2020-12-29 04:33

    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.

提交回复
热议问题