From d0803e4dab8117d2c39fa076a2e7b50ef39380a3 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 12 Jun 2019 11:42:57 -0700 Subject: [PATCH] Make then .then(resolve, reject) API thenable. Fixes #295 --- src/common/TesseractJob.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common/TesseractJob.js b/src/common/TesseractJob.js index 7d54aff..90652bf 100644 --- a/src/common/TesseractJob.js +++ b/src/common/TesseractJob.js @@ -48,14 +48,14 @@ class TesseractJob { * @param {function} reject - called when the job fails */ then(resolve, reject) { - if (this._resolve.push) { - this._resolve.push(resolve); - } else { - resolve(this._resolve); - } - - if (reject) this.catch(reject); - return this; + return new Promise((res, rej) => { + if (!this._resolve.push) { + res(this._result); + } else { + this._resolve.push(res); + } + this.catch(rej); + }).then(resolve, reject); } /**