-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"node": true, | ||
"strict": true, | ||
"eqnull": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var asyncDone = require('async-done'); | ||
|
||
function settle(fn, done){ | ||
asyncDone(fn, function(error, result){ | ||
var settled = {}; | ||
|
||
if(error != null){ | ||
settled.state = 'error'; | ||
settled.value = error; | ||
} else { | ||
settled.state = 'success'; | ||
settled.value = result; | ||
} | ||
|
||
done(undefined, settled); | ||
}); | ||
} | ||
|
||
module.exports = settle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "async-settle", | ||
"version": "0.0.0", | ||
"description": "Settle your async functions - when you need to know all your parallel functions are complete (success or failure)", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "tap ./test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/phated/async-settle" | ||
}, | ||
"keywords": [ | ||
"settle", | ||
"async", | ||
"async-done", | ||
"complete", | ||
"error", | ||
"parallel" | ||
], | ||
"author": "Blaine Bublitz <[email protected]> (http://iceddev.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/phated/async-settle/issues" | ||
}, | ||
"homepage": "https://github.com/phated/async-settle", | ||
"devDependencies": { | ||
"tap": "^0.4.8" | ||
}, | ||
"dependencies": { | ||
"async-done": "^0.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
|
||
var settle = require('../'); | ||
|
||
test('should transform success into settled success values', function(t){ | ||
var val = 'value to be settled'; | ||
settle(function(done){ | ||
done(null, val); | ||
}, function(error, result){ | ||
t.notOk(error, 'error should be undefined'); | ||
t.ok(result, 'result should be defined'); | ||
t.ok(result.state === 'success', 'state should be "success"'); | ||
t.equal(result.value, val, 'value should be the success value'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('should transform errors into settled success values', function(t){ | ||
var err = new Error('Error to be settled'); | ||
settle(function(done){ | ||
done(err); | ||
}, function(error, result){ | ||
t.notOk(error, 'error should be undefined'); | ||
t.ok(result, 'result should be defined'); | ||
t.ok(result.state === 'error', 'state should be "error"'); | ||
t.equal(result.value, err, 'value should be the error value'); | ||
t.end(); | ||
}); | ||
}); |