Empty then on promise

Viewed 546

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.

1 Answers

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...

Related