This topic created in 1687 days ago, the information mentioned may be changed or developed.
5 replies • 2021-10-15 22:38:09 +08:00
 |
|
1
autoxbc Oct 15, 2021 1
你是对的,这个例子并不恰当,为解释 once 硬拗了一个场景,实际并没有多次 emit,once 的效果也没用上
|
 |
|
3
AmiKara Oct 15, 2021
能理解 readFile 只执行了一次,但是多次 for 循环后都返回了一个结果,这是同一个 emit 返回的吗?
|
 |
|
4
autoxbc Oct 15, 2021 1
代码逻辑简化后是这样:
每一次 select 操作,都在 emitter 上挂了一个回调,但是只有第一个 select 触发了 readFile,后面的 select 都因为 status[file] = 'pending' 导致只挂了回调,没有触发 readFile
这唯一的 readFile 得到数据后 emit 了唯一一次,并把前面挂上的回调一一执行,这多个返回结果都是同一个 emit 触发的
所以这个例子是用一个 emit 触发了多个 once,并不是一个 once 被多次 emit 只触发一次,所以算是写跑题了
|