I came across the source code of tiny-async-pool npm package, in there there's this composition
const p = Promise.resolve().then(() => iterator(index, array))
I am a bit confused by this implementation, so I started to do some checks, my understanding is that what it actually does is creating a pending promise, when I log in my terminal I get this:
;(async () => {
const store = []
const promiseFn1 = () => 'I say one'
const promise1 = Promise.resolve().then(() => promiseFn1())
console.log('promise1: ', promise1)
store.push(promise1)
const promiseFn2 = () => 'I say two'
const promise2 = Promise.resolve(promiseFn2())
console.log('promise2: ', promise2)
store.push(promise2)
const promiseFn3 = () => 'I say three'
const promise3 = new Promise((resolve) => resolve(promiseFn3()))
console.log('promise3: ', promise3)
store.push(promise3)
await Promise.all(store)
})()
Is this what the code is doing and if so, is this the only way to create a pending promise that can be stored on an array of promises?
Thanks.