From 96d1e48edd462a02628150f4d0f397b7c9c9c289 Mon Sep 17 00:00:00 2001 From: Page Date: Sun, 15 Jun 2014 12:20:02 +0100 Subject: [PATCH] Use a promise constructor so we can make the code a bit cleaner. --- src/supervisor-update.coffee | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/supervisor-update.coffee b/src/supervisor-update.coffee index 1506ff94..93074e81 100644 --- a/src/supervisor-update.coffee +++ b/src/supervisor-update.coffee @@ -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(