Skip to content

Commit

Permalink
Merge pull request #296 from tmcw/thenable-then
Browse files Browse the repository at this point in the history
Make then .then(resolve, reject) API thenable. Fixes #295

Merged, thanks for contribution 👍
  • Loading branch information
jeromewu committed Jul 4, 2019
2 parents 2a2d051 + d0803e4 commit 5cd2c08
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/common/TesseractJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 5cd2c08

Please sign in to comment.