Where'd Promise#done go?

Domenic Denicola domenic at domenicdenicola.com
Wed Jun 19 07:18:10 PDT 2013

From: Alex Russell [slightlyoff at gmail.com]

> On Wednesday, June 19, 2013, Ron Buckton wrote:

>> Promise#done() doesn’t have the overhead that Promie#then does (allocating a new chained Promise), so it is more efficient if you don’t need to chain.

> That is my only latent argument for #done(), and one that I think I agree with Luke to re-visit at some later date. We can always add.

Given the heroics browsers pull for optimizing unused return values already, this argument never made much sense to me. E.g. Brendan has earlier mentioned SpiderMonkey taking a different code path if it sees `if (regExp.exec(...))`, which only returns a truthy result instead of computing the entire array. It seems like a trivial optimization to notice that nobody's using the return value of `then` and not create a promise to return.

More information about the es-discuss mailing list