Last active
August 29, 2015 14:08
-
-
Save abe33/39a6fa3894592fa658be to your computer and use it in GitHub Desktop.
Requires many Atom packages as a promise
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
atom.packages.requirePackages = (packages...) -> | |
new Promise (resolve, reject) -> | |
required = [] | |
promises = [] | |
failures = [] | |
remains = packages.length | |
solved = -> | |
remains-- | |
return unless remains is 0 | |
return reject(failures) if failures.length > 0 | |
resolve(required) | |
packages.forEach (pkg, i) -> | |
promises.push(atom.packages.activatePackage(pkg) | |
.then (activatedPackage) -> | |
required[i] = activatedPackage.mainModule | |
solved() | |
.fail (reason) -> | |
failures[i] = reason | |
solved() | |
) |
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
atom.packages.requirePackages('minimap', 'find-and-replace') | |
.then ([minimap, find]) -> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment