Comparing version 0.0.9 to 0.0.10
@@ -298,2 +298,15 @@ /* | ||
SuperGroup.prototype.timeout = function (milliseconds) { | ||
if (!this.result) { | ||
if (this._timeout) { | ||
clearTimeout(this._timeout); | ||
} | ||
this._timeout = setTimeout(function () { | ||
this.fail(new Error("timeout")); | ||
// we might not have run the result handler previously: | ||
this._runResultHandlers.apply(this, this.result); | ||
}.bind(this), milliseconds); | ||
} | ||
} | ||
//**************************************************************** | ||
@@ -341,2 +354,9 @@ | ||
SuperGroup.prototype._runResultHandlers = function (err) { | ||
if (this._finished) { return; } | ||
this._finished = true; | ||
if (this._timeout) { | ||
clearTimeout(this._timeout); | ||
} | ||
// if we're running the callback chain, an error occured, and no one | ||
@@ -343,0 +363,0 @@ // attached an error handler, log it out with ff.onerror. |
{ | ||
"name": "ff", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Concise, Powerful Asynchronous Flow Control in JavaScript", | ||
@@ -5,0 +5,0 @@ "engine": [ "node >=0.2.0" ], |
@@ -1,2 +0,2 @@ | ||
# ff: Concise, Powerful Asynchronous Flow Control in JavaScript | ||
# <img src="http://f.cl.ly/items/3K113g321o0n0W0Y0Z33/Fast%20Forward%20Icon%20in%2032x32%20px.png" width=25 height=25> ff: Concise, Powerful Asynchronous JavaScript Flow Control | ||
@@ -18,3 +18,2 @@ ***ff* simplifies the most common use cases for series, parallel, and | ||
- **[Quick Reference & Cheat Sheet](#quick-reference--cheat-sheet)** | ||
- [More Examples](#more-examples) | ||
@@ -164,2 +163,8 @@ ## Intro | ||
#### `f.timeout(milliseconds)` | ||
Set a timeout; if the `ff` chain of steps do not finish after this | ||
many milliseconds, fail with a timeout Error. Works with both deferred | ||
and normal `ff` steps. | ||
## Finally, remember to handle the result! (`.cb`, `.error`, `.success`) | ||
@@ -344,2 +349,3 @@ | ||
f.fail(err); // after this function, fail with this error | ||
f.timeout(200); // abort if it doesn't finish before 200 milliseconds | ||
}, function (arg1, arg2, file1, allFiles, file3Exists, multi1, multi2) { | ||
@@ -367,2 +373,4 @@ // Do something amazing here! | ||
f.fail(err); // failure | ||
// Add a timeout (which would result in a failure with a timeout Error | ||
f.timeout(milliseconds); | ||
// Get the result synchronously, if available (the error argument is on f.result[0]) | ||
@@ -369,0 +377,0 @@ var resultArray = f.result |
@@ -73,2 +73,43 @@ var assert = require("assert"); | ||
describe("#timeout()", function () { | ||
it("should timeout", function (done) { | ||
var f = ff(function () { | ||
f.timeout(20); | ||
setTimeout(f(), 100); | ||
}).error(function (e) { | ||
assert.equal(e.message, "timeout"); | ||
done(); | ||
}).success(function() { | ||
assert.fail(); | ||
}); | ||
}); | ||
it("should timeout with defer", function (done) { | ||
var f = ff.defer(); | ||
f.timeout(20); | ||
setTimeout(function () { | ||
f(); | ||
}, 100); | ||
f.error(function (e) { | ||
assert.equal(e.message, "timeout"); | ||
done(); | ||
}); | ||
f.success(function() { | ||
assert.fail(); | ||
}); | ||
}); | ||
it("should not timeout", function (done) { | ||
var f = ff(function () { | ||
f.timeout(200); | ||
setTimeout(f(), 10); | ||
}).error(function (e) { | ||
assert.fail(); | ||
}).success(function() { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe("#succeed()", function () { | ||
@@ -75,0 +116,0 @@ it("should work", function (done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31057
661
384