Use a promise constructor so we can make the code a bit cleaner.

This commit is contained in:
Page 2014-06-15 12:20:02 +01:00 committed by Pablo Carranza Vélez
parent a0f9219cb3
commit 96d1e48edd

View File

@ -21,18 +21,14 @@ exports.update = ->
console.log('Fetching updated supervisor:', updateImage)
docker.createImageAsync(fromImage: updateImage)
.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.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
stream.on('end', resolve)
.then ->
console.log('Tagging updated supervisor:', updateImage)
docker.getImage(updateImage).tagAsync(