Skip to content

Instantly share code, notes, and snippets.

@abe33
Last active August 29, 2015 14:08
Show Gist options
  • Save abe33/39a6fa3894592fa658be to your computer and use it in GitHub Desktop.
Save abe33/39a6fa3894592fa658be to your computer and use it in GitHub Desktop.
Requires many Atom packages as a promise
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()
)
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