Search code examples
javascriptes6-promisedeferred

Is there a native way to do deffered promises in Javascript in 2019?


This question here - from 2014 - outlines various ways to do a deferred promise:

Resolve Javascript Promise outside function scope

There is this MDN documentation about Deferred object does say that there is Promise.defer() - but that it is obsolete.

Is there a standard way to do a deferred Promise in Javascript now? I'm otherwise likely to implement one of the Deffered objects in that original question.


Solution

  • Is there a standard way to do a deferred Promise in Javascript now? I'm otherwise likely to implement one of the Deffered objects in that original question.

    No. There is no standard way of doing this in the current versions of Javascript. Apparently, those shepherding the Promise specification believe the actual need for it (cases where the Promise executor function simply won't work) is rare enough that they'd rather not add it to the standard. There may also be a belief that if they add it to the standard, too many people would use it for situations where it shouldn't be used (cases where using the promise executor would make for better code). Obviously, that's all someone's opinion, but those who work on those standards get to decide what opinion to go with.

    As you appear to know there are some pretty simple work-arounds to just define your own. As I previously indicated in the comments, here are a couple of relevant posts on the subject, including code for work-arounds: When would someone need to create a deferred and Deferred object in ES6.