Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Create a pending promise ES6

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: enter image description here

;(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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!