5

During work, I stumbled upon this line inside our codebase (designed to run in the browser). Is there any effect in this line? It seems unnecessary to me, but before removing it, I want to be absolutely sure that I am not overlooking some quirky promise special behaviour that this line does.

// Chain the finishPromise to our global finish chain.
this.finishPromise = this.finishPromise.then();

Next to that line, it is awaited some times, is initialized as Promise.resolve(), and never else overwritten as far as I can see.

Erik Brendel
  • 683
  • 9
  • 23
  • What is the use of the `this.finishPromise` after that line? Can you add more details of the context around this? – rleiva93 Sep 01 '20 at 15:40
  • I adjusted the question accordingly - it is initialized as resolved, awaited a few times, but that's it. – Erik Brendel Sep 01 '20 at 15:52

1 Answers1

2

Assuming this is a native JavaScript promise or anything else that's Promises/A+-compatible and doesn't have custom side-effects,¹ it's valid (JS spec, Promises/A+ spec) — which surprised me slightly — but useless and doesn't have any effect. You can safely remove it.


¹ "...and doesn't have custom side-effects..." The comment above it saying "Chain the finishPromise to our global finish chain" makes me wonder if this is a promise subclass (or worse, a monkey-patched version of the normal Promise.prototype.then) with some kind of side effect. But it could just as easily have been explaining something that was originally passed to then and has been subsequently removed...

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875