redux-saga generator嵌套执行的阻塞与非阻塞

1.generator调用generator

one中yield另一个generatoranother

function*another(params){
    // ...
}

function*one(params,{ call, put }){
    // ...
    yield another(params)
    // ...
}

1.yield后面接 generator(),带括号

2.可以传入参数,another也能接收到

3.another的执行是会中断one的执行的,也就是说,
one会得到another执行完了之后才继续往后执行

另外

yield another(params)
yield call(another,params)  

这两种写法是等价的,
call的作用就是把函数和参数并列排列

2. generator中put另一个action

function*one(params,{ call, put }){
    // ...
    yield put({ type: 'another' })
    // ...
}

这样one是不会等待的another的,
直接就往后走了

猜你喜欢

转载自blog.csdn.net/sinat_24070543/article/details/81123094