Deferred

Deferred

A basic class to create a promise with its resolve and reject function in the same object.

Instances of this class are never returned by any function of this library but it is used internally and can be useful to code other asynchronous helpers.


Constructor

# new Deferred()

Constructs a deferred object.

Example
import { Deferred, asyncRoot, sleep } from 'modern-async'

asyncRoot(async () => {
  const deferred = new Deferred()

  sleep(10).then(() => {
    deferred.resolve('test')
  })

  console.log(await deferred.promise) // will wait 10ms before printing 'test'
})

Members

# promise :Promise

(Read-only) The promise.

Type:
  • Promise

# reject :function

(Read-only) The reject function

Type:
  • function

# resolve :function

(Read-only) The resolve function.

Type:
  • function