1.3.4 • Published 3 years ago

waiter-promise v1.3.4

Weekly downloads
11
License
MIT
Repository
github
Last release
3 years ago

waiter-promise -- an enhanced promise library

Waiter is one of Deferred implementation, but with more helpful properties. We split Promise's resolve and reject method out of the declaration, know about settled status, and get result of resolve or reason of reject anytime.

install

npm i -S waiter-promise

# or with yarn
yarn add waiter-promise

use

Use in JavaScript Promise:

import Waiter from 'waiter-promise'

const waiterA = new Waiter()

console.log(waiterA.settled) // -> false
waiterA.then(() => {
  console.log(waiterA.result, waiterA.settled) // -> something result, true
})

const waiterB = new Waiter()
waiterB.catch(() => {
  console.log(waiterB.reason, waiterB.settled) // -> reject reason, true
})

waiterA.resolve('something result')
waiterB.reject('reject reason')

Use with async/await:

import Waiter from 'waiter-promise'

const waiter = new Waiter<string>()

const receive = async (): Promise<void> => {
  const res = await waiter.promise
  console.log(res)
}

const send = () => waiter.resolve('hello world')

send()
receive() // output: hello world
1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago