ES6 - 同时收益率和收益率

时间:2017-07-05 11:40:16

标签: javascript asynchronous yield redux-saga

我有这个,

function*(a){
 if (a) {
    yield API.callRoute();
    return;
  }
  // other stuff that is blocked by return
}

我想要这个:

function*(a){
  if (a) {
    return yield API.callRoute(); // one fewer line of code
  }
  //...
}

可行?为什么?为什么不呢?

1 个答案:

答案 0 :(得分:1)

是的,它可行,但您的第二个代码段returnyield表达式的结果。如果您不想要,但要使其完全等同于您的第一个代码段,请使用

return void yield API.callRoute();
但是,当差异很大时,可能不值得将这条线缩短。

相关问题