Created
March 17, 2015 21:10
-
-
Save jonknapp/75727b4923bfffc41710 to your computer and use it in GitHub Desktop.
promises + addInitializer
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
var Application = { | |
addInitializer: function(func) { | |
return new Promise(func); | |
} | |
}; | |
Promise.all([ | |
Application.addInitializer(require('./initializers/something')), | |
Application.addInitializer(require('./initializers/something-else')), | |
Application.addInitializer(require('./initializers/blah')) | |
]).then(function() { | |
console.log('success', arguments); | |
}, function() { | |
console.log('failure', arguments); | |
}); |
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
module.exports = function(resolve, reject) { | |
setTimeout(function() { | |
resolve(new Error('C')); | |
}, 1000); | |
}; |
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
module.exports = function(resolve, reject) { | |
resolve('B'); | |
}; |
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
module.exports = function(resolve, reject) { | |
resolve('A'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment