我正在浏览 redux-saga 频道文档。我遇到代码的地方:
export function* saga() {
const chan = yield call(countdown, value)
try {
while (true) {
let seconds = yield take(chan)
console.log(`countdown: ${seconds}`)
}
} finally {
if (yield cancelled()) {
chan.close()
console.log('countdown cancelled')
}
}
}
如您所见,这是一个永远不会结束的无限循环,您应该调用 break 或 throw 和异常。但在上面的例子中,情况并非如此。上面的代码或调用函数中没有引发中断或异常。上面的无限循环怎么可能结束并到达finally块?
见:http: //yelouafi.github.io/redux-saga/docs/advanced/Channels.html