consti = pipe( toAsync([1, 2, 3, 4]), delay(10), // an async operation that takes 10ms each timeout(18, (count) => { // timeout occurred (failed to process all items); // only 'count' number of items were processed. }) );
Note that the examples above may not always produce a consistent result, as they rely on a race condition,
which depends on the OS, your current CPU load and JavaScript engine.
Type Parameters
T
Parameters
ms: number
Timeout in milliseconds. Passing in a negative number deactivates the timeout.
Optionalcb: ((count) => void)
Notification of when iteration stops due to the timeout,
with parameter count - the number of items processed before timeout.
Ends iteration after a specified number of milliseconds (from the beginning of iteration). When
ms
< 0, the timeout is deactivated.Optional callback
cb
is invoked when timeout is reached before iteration is over.It works synchronously in a similar way:
Note that the examples above may not always produce a consistent result, as they rely on a race condition, which depends on the OS, your current CPU load and JavaScript engine.