Is it safe to resolve a promise multiple times?

As I understand promises at present, this should be 100% fine. The only thing to understand is that once resolved (or rejected), that is it for a defered object – it is done.

If you call then(...) on its promise again, you immediately get the (first) resolved/rejected result.

Additional calls to resolve() will not have any effect.

Below is an executable snippet that covers those use cases:

var p = new Promise((resolve, reject) => {

p.then(x => console.log('resolved to ' + x))
 .catch(x => console.log('never called ' + x));

p.then(x => console.log('one more ' + x));
p.then(x => console.log('two more ' + x));
p.then(x => console.log('three more ' + x));

Leave a Comment