1
我正在写一个node.js程序,它利用fibrous库在我的部分代码中维护同步控制。node.js中的同步时序
在一个辅助函数中,我需要完成一个超时,但不能使用setTimeout()
,因为它在fibrous的上下文中不起作用。
这是我想出了替代:
startTimer = new Date()
startSecondTimer = new Date()
while startSecondTimer - startTimer < 10000
startSecondTimer = new Date()
我不是很舒服创造几千Date
对象支持这一工作流程,但我不能确定这里是什么更好的方法可能是。
是否有更优化的方式来编写同步超时样式函数?
看起来你可以很容易地使用'setTimeout' [在'wait']里面(https://github.com/goodeggs/fibrous#4-waiting-on-a-callback),或者直接使用[Fiber's '睡眠'执行](https://github.com/laverdet/node-fibers#sleep)? – Bergi