       actom.activatePackage(name) if activateOnFailure
       callback(new Error("Installing '#{name}' failed."))
 
+  new BufferedProcess({command, args, exit})
+
 uninstall = ({name}, callback) ->
   atom.deactivatePackage(name) if atom.isPackageActive(name)
 
-  apm = require.resolve '.bin/apm'
-  apmProcess = spawn(apm, ['uninstall', name])
-  apmProcess.on 'close', (code) =>
+  command = require.resolve '.bin/apm'
+  args = ['uninstall', name]
+  exit = (code) ->
     if code is 0
       atom.unloadPackage(name) if atom.isPackageLoaded(name)
       callback()
     else
       callback(new Error("Uninstalling '#{name}' failed."))
 
+  new BufferedProcess({command, args, exit})
+
 module.exports = {renderMarkdownInMetadata, install, uninstall, getAvailable}

{spawn} = require 'child_process'
roaster = require 'roaster'
async = require 'async'


  queue.drain = callback

getAvailable = (callback) ->
  command = require.resolve '.bin/apm'
  args = ['available', '--json']
  output = []
  stdout = (lines) -> output.push(lines)
  exit = (code) ->
    if code is 0
      try
        packages = JSON.parse(output.join()) ? []
      catch error
        callback(error)
        return
