Modularization, you can require only the needed tools:
import fromEvent from 'promise-toolbox/fromEvent'
Better naming, to avoid conflicting with synchronous tools, symbols
are also exported with a p
prefix:
import { pFromEvent, pMap } from 'promise-toolbox'
delay()
now also accepts a value as second parameter:
// still valid: using delay as a pseudo method with existing promises
promise::delay(1e3).then(value => {
// ...
})
// new usage: using delay as a function with plain values
delay(1e3, 'foo').then(value => {
// ...
})
asyncFn
can be used to turn a generator to an async function:
const f = asyncFn(function * () {
console.log('foo')
console.log(yield delay(1e3, 'bar'))
return 'baz'
})
asyncFn.cancelable
can be used to turn a generator to an cancelable async
function:
const f = asyncFun.cancelable(function * (cancelToken) {
console.log('foo')
console.log(yield delay(1e3, 'bar'))
return 'baz'
})
const cancelSource = CancelToken.source()
f(cancelSource.token).catch(reason => {
console.log(reason)
})
cancelToken.cancel()
BREAKING CHANGE: attempt
, cancellable
, lastly
and nodeify
aliases
are no longer available, use pTry
, cancelable
, pFinally
and unpromisify
.
BREAKING CHANGE: catchPlus
has been renamed to catch
(pCatch
).
BREAKING CHANGE: parameters order in promisifyAll
's mapper has
been changed to be similar to forEach
and
map
: value, name, object
.
BREAKING CHANGE: catch
, finally
, reflect
, tap
& timeout
now only works with promises.
BREAKING CHANGE: unpromisify
does not catch synchronous
exceptions.
BREAKING CHANGE: join
has been removed because unnecessary.
BREAKING CHANGE: reflect
's isResolved
has been removed because
confusing and does not provide new info.
BREAKING CHANGE: CancelToken.race
& CancelToken#fork
have been removed
in favor of passing tokens to CancelToken.source
.
CancelToken.race
:
// Before:
const token = CancelToken.race([ token1, token2 ])
// After:
const { token } = CancelToken.source([ token1, token2 ])
CancelToken#fork
:
// Before:
const token = otherToken.fork(cancel => {
// ...
})
// After:
const { cancel, token } = CancelToken.source([ otherToken ])