0

I've got troubles with awaiting Promise.all(), it never continues after that. I've got helper function for creating cancelable promises:

create(promise) {
    let hasCanceled_ = false

    const wrappedPromise = new Promise((resolve, reject) => {
      promise.then(
        val => (hasCanceled_ ? reject({ isCanceled: true }) : resolve(val)),
        error => (hasCanceled_ ? reject({ isCanceled: true }) : reject(error))
      )
    })

    const cancelablePromise = {
      promise: wrappedPromise,
      cancel() {
        hasCanceled_ = true
      }
    }

    return cancelablePromise
  }

then I created promises like following way:

const timelinePromise = this.pendingPromises.create(
    this.fetchWholeTimeline(false)
)
const confJobsPromise = this.pendingPromises.create(
    this.fetchWorkspaceJobConfigurationJobs(false)
)

and at least I'm executing this piece of code:

const [timelineResponse, confJobsResponse] = await Promise.all(
    timelinePromise.promise,
    confJobsPromise.promise
)

console.log(timelineResponse)
console.log(confJobsResponse)

The console.logs are never executed... What I'm doing wrong here?

ketysek
  • 1,159
  • 1
  • 16
  • 46
  • 1
    Btw, avoid the [`Promise` constructor antipattern](https://stackoverflow.com/q/23803743/1048572?What-is-the-promise-construction-antipattern-and-how-to-avoid-it). Your `create` function should simply do `promise.then(result => { if (hasCancelled) throw {…} else return result; }, err => { if (hasCancelled) throw {…} else throw err; })` – Bergi Feb 28 '19 at 13:06

2 Answers2

0

Promise.all expect an array (iterable actually) of promises as the single parameter.

Sergiu Paraschiv
  • 9,929
  • 5
  • 36
  • 47
0

the Promise.all method expects an array of promisses.

Promise.all([promiseA, promiseB])
iacobalin
  • 523
  • 2
  • 9