1.0.6 • Published 10 months ago

aasy v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

aasy

Async - easy.

Zero-library Promise wrapper without pain.

Make Promise without undefined behavior(almost).

Reason to use aasy

  1. Typescript types. Promise stantard generic is not accepts Reject generic. aasy does.
  2. Less undefined behavior, when using safe function.
  3. Inherited from built-in Promise object
  4. ESM and CJS support.
type Async<Value, Error = unknown> = intrinsic // from native Promise + API

Wanna be contributor?

See contribute guide

API

safe

Call promise and do not throw an error even if get rejected status.

Arguments: value - Promise

Returns:

  • Promise<Object>
    • success boolean
    • value - Promise Fulfilled result
    • error - Promise Reject reason
    • unwrap Function - Function that accepts new error and returns resolved value. See examples to see it in action

Example safe

import Async from 'aasy';
const promiseThatFails = await Async.safe(Async.reject(123));

promiseThatFails.success // false
promiseThatFails.value // undefined
promiseThatFails.error // 123
promiseThatFails.unwrap() // throws "123"
promiseThatFails.unwrap("Undefined Behavior") // throws "Undefined Behavior"

const promiseSuccess = await Async.safe("Hello!");

promiseSuccess.success // true
promiseSuccess.error // undefined
promiseSuccess.value // "Hello!"
promise.unwrap() // "Hello!"
const value = promise.unwrap("Undefined behavior") // error will be ignored
console.log(value) // "Hello!"

from

Transforms Promise | PromiseLike value into async instance.

Example from

import Async from 'aasy';

const promiseFromSomewhere = fetch(...);
const promise = Async.from(promiseFromSomewhere);
// or you can use await to get result from promise
const awaitdResult = await Async.from(promiseFromSomewhere);

Async.resolve

Inherited from Promise

Async.reject

Inherited from Promise

Async.all

Inherited from Promise

Async.any

Inherited from Promise

then

Inherited from Promise

catch

Inherited from Promise

finally

Inherited from Promise

Tech Stack

  • pnpm
  • esbuild
  • typescript
  • husky
  • github actions
  • jest
  • eslint