Base functionality used throughout XY Labs TypeScript/JavaScript libraries
npm install @xylabs/promise[![logo][]](https://xylabs.com)
[![main-build][]][main-build-link]
[![npm-badge][]][npm-link]
[![npm-downloads-badge][]][npm-link]
[![jsdelivr-badge][]][jsdelivr-link]
[![npm-license-badge][]](LICENSE)
[![codacy-badge][]][codacy-link]
[![codeclimate-badge][]][codeclimate-link]
[![snyk-badge][]][snyk-link]
[![socket-badge][]][socket-link]
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
@xylabs/promise
*
- PromiseExSubFunc
- PromiseExFunc
- PromiseExValueFunc
- AnyNonPromise
- Promisable
- PromisableArray
- OptionalPromisable
- OptionalPromisableArray
- NullablePromisable
- NullablePromisableArray
- AsyncMutex
- fulfilled
- fulfilledValues
- isPromise
- rejected
- toPromise
*
- Promise\<T\>
T
V = void
``ts`
new PromiseEx
#### func
PromiseExFunc\<T\>
#### value?
V
PromiseEx\<T, V\>
`ts`
Promise
`ts`
optional cancelled: boolean;
`ts`
then
onfulfilled?,
onrejected?,
onvalue?): Promise
Attaches callbacks for the resolution and/or rejection of the Promise.
#### TResult1
TResult1 = T
#### TResult2
TResult2 = never
#### onfulfilled?
The callback to execute when the Promise is resolved.
null | (value) => TResult1 \| PromiseLike\<TResult1\>
#### onrejected?
The callback to execute when the Promise is rejected.
null | (reason) => TResult2 \| PromiseLike\<TResult2\>
#### onvalue?
(value?) => boolean
Promise\<TResult1 \| TResult2\>
A Promise for the completion of which ever callback is executed.
`ts`
Promise.then
*
`ts`
value(onvalue?): PromiseEx
#### onvalue?
(value?) => boolean
PromiseEx\<T, V\>
*
`ts`
function fulfilled
For use with Promise.allSettled to filter only successful results
T
PromiseSettledResult\<T\>
val is PromiseFulfilledResult
*
`ts`
function fulfilledValues
For use with Promise.allSettled to reduce to only successful result values
T
T[]
PromiseSettledResult\<T\>
T[]
`ts`
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce(fulfilledValues, [] as string[])
// results === [ 'resolved' ]
`ts`
const resolved = Promise.resolve('resolved')
const rejected = Promise.reject('rejected')
const settled = await Promise.allSettled([resolved, rejected])
const results = settled.reduce
// results === [ 'resolved' ]
*
`ts`
function isPromise(value): value is Promise
unknown
value is Promise
*
`ts`
function rejected
For use with Promise.allSettled to filter only rejected results
T
PromiseSettledResult\<T\>
val is PromiseRejectedResult
*
`ts`
function toPromise
T
Promisable\<T\>
Promise\<T\>
*
`ts`
then: () => unknown;
unknown
*
`ts`
type AnyNonPromise = Exclude
*
`ts`
type AsyncMutex
T
Used to document promises that are being used as Mutexes
*
`ts`
type NullablePromisable
T
V = never
*
`ts`
type NullablePromisableArray
T
V = never
*
`ts`
type OptionalPromisable
T
V = never
*
`ts`
type OptionalPromisableArray
T
V = never
*
`ts`
type Promisable
T
V = never
*
`ts`
type PromisableArray
T
V = never
*
`ts`
type PromiseExFunc
T
PromiseExSubFunc\<T, void\>
PromiseExSubFunc\<T, void\>
void
*
`ts`
type PromiseExSubFunc
T
TResult = T
T
TResult
*
`ts`
type PromiseExValueFunc
V
V
boolean`
Part of sdk-js
- Arie Trouw (arietrouw.com)
- Matt Jones
- Joel Carter
- Jordan Trouw
> See the LICENSE file for license details
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
[main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
[main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
[npm-badge]: https://img.shields.io/npm/v/@xylabs/promise.svg
[npm-link]: https://www.npmjs.com/package/@xylabs/promise
[codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
[codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
[codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
[snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
[snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/promise
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/promise
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/promise/badge
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/promise
[socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/promise
[socket-link]: https://socket.dev/npm/package/@xylabs/promise