我有一个线程,它从web服务轮询数据,然后将其发送到不同的类来处理数据。数据的处理可能需要很长时间,有时甚至超过在线程内部调用轮询函数的计时器间隔。
我想保护这个轮询函数,即在处理数据的过程中,不要进入该函数。
我的流程是这样的
workerThread -> start timer -> that invoking the polling method ->
the polling method gets the data and send it to processing > mean while this polling function can be call
由libuv实现的Node事件循环由特定阶段组成。poll阶段用于阻塞等待I/O任务,并随后运行其回调。等待的时间取决于计时器、超时和通过setImmediate()注册的回调的存在。例如,如果我们有一个setImmediate()回调,则持续时间设置为0。
如果目前我们正在进入poll阶段,已经发生了一些I/O事件,怎么办?它们的回调应该立即执行,而不需要在setTimeout()或setImmediate()中注册回调视图。
The
当事件循环进入轮询阶段,并且没有调度计时器时,将发生以下两种情况之一:
如果轮询队列不是空的,则事件循环将遍历其回调队列,同步执行它们,直到队列
我正在经历节点的事件循环,我感到非常困惑。上面写着-
timers: this phase executes callbacks scheduled by setTimeout() and
setInterval().
I/O callbacks: executes almost all callbacks with the exception of close callbacks, the ones scheduled by timers, and setImmediate().
idle, prepare: only used internally.
poll: retrieve new