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) console.log("Pulling image:", app.imageId)
docker.createImageAsync(fromImage: app.imageId) docker.createImageAsync(fromImage: app.imageId)
.then (stream) -> .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(reject))
else
stream.pipe(es.wait((error, text) -> reject(text))
if stream.headers['content-type'] is 'application/json' stream.on('end', resolve)
stream.pipe(JSONStream.parse('error'))
.pipe es.mapSync (error) ->
deferred.reject(error)
else
stream.pipe es.wait (error, text) -> deferred.reject(text)
stream.on 'end', -> deferred.resolve()
return deferred.promise
.then -> .then ->
console.log("Creating container:", app.imageId) console.log("Creating container:", app.imageId)
ports = {} ports = {}