Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Latest commit

 

History

History
26 lines (16 loc) · 786 Bytes

File metadata and controls

26 lines (16 loc) · 786 Bytes

Use Case #4

Name: Promise constructor allows for Promises that never resolve.

Consider the following code

;(new Promise(() => {})).then(() => console.log('a executed'))
;(Promise.resolve('x')).then(() => console.log('b executed'))

// outputs
// b executed

What happens

The first Promise (new Promise(() => {})) will never resolve or reject.

Why it happens

It is possible to create a Promise using the Promise constructor which does not resolve or reject (by never calling resolve() or reject())

What can we maybe do better

  • Provide a warning when neither resolve or reject are referenced in the promise constructor.
  • Optionally provide a warning when a Promise remains alive for more than N seconds and was neither resolved nor rejected.