UNPKG

workflow-4-node

Version:

Workflow 4 Node is a .NET Workflow Foundation like framework for Node.js. The goal is to reach feature equivalence and beyond.

27 lines (23 loc) 798 B
var Bluebird = require("bluebird"); var is = require("./is"); var async = Bluebird.coroutine; var asyncHelpers = { async: async, aggressiveRetry: async(function* (asyncFunc, until, timeout, timeoutError) { timeoutError = timeoutError || function () { return new Error("Retry timeout."); }; var startTime = new Date().getTime(); var waitTime = 0; var waitCount = 0; var result = yield asyncFunc(); while (!until(result)) { if (new Date().getTime() - startTime > timeout) throw timeoutError(); yield Bluebird.delay(waitTime); waitTime = Math.min(++waitCount * 250, 3000); result = yield asyncFunc(); } return result; }) } module.exports = asyncHelpers;