I'm writing a node.js program that makes use of the fibrous library to maintain synchronous control in part of my code.
In a helper function, I need to complete a timeout, but cannot use setTimeout()
because it will not work in the context with fibrous.
This is what I came up with instead:
startTimer = new Date()
startSecondTimer = new Date()
while startSecondTimer - startTimer < 10000
startSecondTimer = new Date()
I'm not very comfortable with creating several thousand Date
objects to support this workflow, but I'm not certain what a better approach here might be.
Is there a more optimal way to write a synchronous timeout-style function?