Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instantiate a resolved promise in ES2015

What is the canonical way to create a resolved promise in ES 2015?

like image 700
Ben Aston Avatar asked Jun 09 '16 14:06

Ben Aston


People also ask

How do you initialise a promise?

This function is a promise and is called by an execute function. If execute is called twice, the second must wait the initialization then continue the execution. I wrote this code, but the second call of execute is always waiting and doesn't never return.

How do I return a resolved promise?

resolve() method in JS returns a Promise object that is resolved with a given value. Any of the three things can happened: If the value is a promise then promise is returned. If the value has a “then” attached to the promise, then the returned promise will follow that “then” to till the final state.

Does promise return After resolve?

The Promise. resolve() method "resolves" a given value to a Promise . If the value is a promise, that promise is returned; if the value is a thenable, Promise. resolve() will call the then() method with two callbacks it prepared; otherwise the returned promise will be fulfilled with the value.

How do you resolve an array of promises?

all() The Promise. all() method takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises. This returned promise will fulfill when all of the input's promises have fulfilled, or if the input iterable contains no promises.


1 Answers

The Promise.resolve class method returns a promise that is instantiated as resolved with a value you can specify:

var promise = Promise.resolve(100); 
like image 198
Yotam Ofek Avatar answered Sep 27 '22 20:09

Yotam Ofek