From b3f9f9b1ef4fc0038641983f71e0185dd5f5cfd3 Mon Sep 17 00:00:00 2001 From: Page Date: Mon, 9 Jun 2014 15:38:42 +0100 Subject: [PATCH] Switch to using the Promise constructor rather than deferred, it allows for slightly nicer code. Also add some parens in appropriate places. --- src/application.coffee | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/application.coffee b/src/application.coffee index 5561843d..c33ca7bf 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -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(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("Creating container:", app.imageId) ports = {}