From 3dcdb367919a84232edffeb181f4375f04d4a0d4 Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Sat, 25 Mar 2017 04:20:28 -0700 Subject: [PATCH 1/4] Promises are a great form of handling concurrency where a single value is passed around --- lib/command.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/command.js b/lib/command.js index 2ff464fe..a24fe90c 100644 --- a/lib/command.js +++ b/lib/command.js @@ -82,13 +82,7 @@ module.exports = function (proto) { * @return {Object} gm */ - proto.write = function write (name, callback) { - if (!callback) callback = name, name = null; - - if ("function" !== typeof callback) { - throw new TypeError("gm().write() expects a callback function") - } - + proto.write = function write (name) { if (!name) { return callback(TypeError("gm().write() expects a filename when writing new files")); } @@ -96,10 +90,14 @@ module.exports = function (proto) { this.outname = name; var self = this; - this._preprocess(function (err) { - if (err) return callback(err); - self._spawn(self.args(), true, callback); - }); + return new Promise((resolve, reject) => { + this._preprocess(function (err) { + if (err) { + return reject(err) + }; + return self._spawn(self.args(), true, resolve); + }); + }) } /** From ae975dda9b7ba0bfbaf818b6abccc64dcbbbc28d Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Sat, 25 Mar 2017 04:22:37 -0700 Subject: [PATCH 2/4] Fixing whitespace What the hell, github? --- lib/command.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/command.js b/lib/command.js index a24fe90c..029cb7eb 100644 --- a/lib/command.js +++ b/lib/command.js @@ -90,6 +90,7 @@ module.exports = function (proto) { this.outname = name; var self = this; + return new Promise((resolve, reject) => { this._preprocess(function (err) { if (err) { From 687c85bed90f0e4ed20095fcf46b11be763ed52b Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Sat, 25 Mar 2017 04:23:53 -0700 Subject: [PATCH 3/4] Another shot at fixing github's whitespace annoyances? --- lib/command.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/command.js b/lib/command.js index 029cb7eb..e83d9612 100644 --- a/lib/command.js +++ b/lib/command.js @@ -91,14 +91,14 @@ module.exports = function (proto) { var self = this; - return new Promise((resolve, reject) => { - this._preprocess(function (err) { - if (err) { - return reject(err) - }; - return self._spawn(self.args(), true, resolve); - }); - }) + return new Promise((resolve, reject) => { + this._preprocess(function (err) { + if (err) { + return reject(err) + }; + return self._spawn(self.args(), true, resolve); + }); + }) } /** From 7651eddbbc5030095de104f95fcc020664672d8a Mon Sep 17 00:00:00 2001 From: Kurtis Rainbolt-Greene Date: Sat, 25 Mar 2017 04:25:46 -0700 Subject: [PATCH 4/4] gm supports node before arrow syntax --- lib/command.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/command.js b/lib/command.js index e83d9612..43ac4914 100644 --- a/lib/command.js +++ b/lib/command.js @@ -91,8 +91,8 @@ module.exports = function (proto) { var self = this; - return new Promise((resolve, reject) => { - this._preprocess(function (err) { + return new Promise(function writeResolution (resolve, reject) { + this._preprocess(function preprocessCallback (err) { if (err) { return reject(err) };