promises-aplus / promises-spec

An open standard for sound, interoperable JavaScript promises—by implementers, for implementers.
https://promisesaplus.com/
Creative Commons Zero v1.0 Universal
1.84k stars 171 forks source link

Example for abstract definition: "promise resolution procedure" #214

Closed BairDev closed 8 years ago

BairDev commented 8 years ago

Hi, I don't quite get the meaning of this sentence:

The promise resolution procedure is an abstract operation taking as input a promise and a value, which we denote as [...].

Can this mean something like (Pseudocode):

function(promise, x) {
   if (promise === x) {
      throw new TypeError();
   }  
   // do more stuff
}

If this is the case, does this function has anything to do with resolving a promise? To be more precise: what is the meaning of resolution?

bergus commented 8 years ago

Have a look at http://stackoverflow.com/questions/29268569/what-is-the-correct-terminology-for-javascript-promises Yes, resolution is exactly the substantive for resolving. To resolve a promise, you run the promise resolution procedure with a value x.

BairDev commented 8 years ago

Alright, thanks. I mainly was confused because of two points, both regarding the use of Promises in the AngularJS/$q context.

But anyway, angular.$q might not follow the spec (this spec), then it is not a good example.

ForbesLindesay commented 8 years ago

The promise resolution procedure is an abstract operation. What this means is that it is a description of some functionality for use within the spec, rather than a function or method that should actually be exposed to users. Some promise implementations do have a function very similar to this one, many do not.

bergus commented 8 years ago

$q.defer().resolve should actually be called $q.defer().fulfill. Am I right with this assumption?

No. resolve does not necessarily fulfill the promise. You can resolve with a rejected promise, leading to a rejection, or you can resolve with a never-settling promise, leading to nothing but the lock-in.

BairDev commented 8 years ago

Many thanks for the background stuff. I was not aware of this branch in $q.