Created
June 26, 2014 03:25
-
-
Save j0lvera/176fe2b6bb238ae779ff to your computer and use it in GitHub Desktop.
Promises using when.js
This file contains hidden or 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
function finder(records){ | |
// instance of when.defer method | |
var deferred = when.defer(); | |
setTimeout(function () { | |
records.push(3, 4); | |
// save result | |
deferred.resolve(records); | |
}, 500); | |
// expose result | |
return deferred.promise; | |
} | |
function processor(records) { | |
// instance of when.defer method | |
var deferred = when.defer(); | |
setTimeout(function () { | |
records.push(5, 6); | |
// save result | |
deferred.resolve(records); | |
}, 500); | |
// expose result | |
return deferred.promise; | |
} | |
finder([1,2]) | |
.then(processor) | |
.then(function(records) { | |
console.log(records); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment