2017-12-13 7 views
1

redux-sagaでは、callforkjoinのどちらをお勧めしますか?例えばredux-saga:call vs fork and join

、これを行うことの長所と短所は何をしている、HTTP APIを呼び出す:この対

const result = yield call(apiWrapperFunction, arg1, arg2) 

const task = yield fork(apiWrapperFunction, arg1, arg2) 
const result = yield join(task) 

答えて

2

ないようにずっと私の知る限り、 forkjoinの間でタスクを取り消すことができます。

const task = yield fork(api, arg); 

if (someCondition) { 
    yield cancel(task); 
} 

const result = yield join(task); 

// Now a no-op since `join` blocked for the task to finish 
cancel(task); 

あなたの代わりにspawnを使用する場合の違いは、道大きいです。 デタッチされたフォークが作成されます。これは、親タスクが(たとえば)場合に自動的にキャンセルされません。