Switch to using the Promise constructor rather than deferred, it allows for slightly nicer code. Also add some parens in appropriate places.

This commit is contained in:
Page 2014-06-09 15:38:42 +01:00 committed by Pablo Carranza Vélez
parent 4d5c18ec6f
commit b3f9f9b1ef

View File

@ -37,18 +37,14 @@ exports.start = start = (app) ->
console.log("Pulling image:", app.imageId)
docker.createImageAsync(fromImage: app.imageId)
.then (stream) ->
deferred = Promise.defer()
return new Promise (resolve, reject) ->
if stream.headers['content-type'] is 'application/json'
stream.pipe(JSONStream.parse('error'))
.pipe es.mapSync (error) ->
deferred.reject(error)
.pipe(es.mapSync(reject))
else
stream.pipe es.wait (error, text) -> deferred.reject(text)
stream.pipe(es.wait((error, text) -> reject(text))
stream.on 'end', -> deferred.resolve()
return deferred.promise
stream.on('end', resolve)
.then ->
console.log("Creating container:", app.imageId)
ports = {}