Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of Promise.resolve(null)

I'm looking at firebase sdk and there is a line where the getAuth token method returns a Promise that resolves to null? I've seen this pattern a few times and am confused what the purpose of this is.

https://github.com/firebase/firebase-js-sdk/blob/ee610626bef1f6f05852041b2161c01c5e99aa59/packages/app/src/firebaseApp.ts#L67

like image 470
user1099123 Avatar asked Nov 30 '25 01:11

user1099123


1 Answers

I know this is an old question. But thought it worth mentioning. Promise.resolve(null) immediately resolves the promise, but the delegate you pass to .then(()=> {}) on the returned Promise will be placed on the microtask queue. Similar to window.setTimeout(()=> {}, 0); (not exactly the same, but very similar).

I've seen this documented on MDN, but I cannot find the page now. If anyone does find that page feel free to edit my answer.

like image 98
Ken Hadden Avatar answered Dec 02 '25 04:12

Ken Hadden