Is there a reason to have an empty promise?
I canβt think of many. One use case is a value that you can pass to Promise.race and expect it to always take another option.
Look Are JavaScript forever awaiting promises bad? and is it safe not to allow or reject the promise .
This reminds me of doing setTimeOut(fn, 0) , and I wonder if it has a similar effect.
No, absolutely not. setTimeout will eventually call the callback, but new Promise(() => {}).then(β¦) never will. This is more like moving from Infinity to setTimeout (which really doesn't really work ).
Perhaps you are thinking of Promise.resolve().then(β¦) or new Promise(r => r()).then(β¦) , which will call the callback function immediately, but asynchronously.
source share