3.4 Redux-Saga
Call vs Fork
function fn() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('hello saga');
}, 2000);
});
}
function* fetchData() {
// 等待 2 秒後,印出歡迎詞(阻塞)
const greeting = yield call(fn);
console.log('greeting: ', greeting);
// 立即打印 task 對象(非阻塞)
const task = yield fork(fn);
console.log('task: ', task);
}Last updated