aasy
v1.0.6
Published
Make Promise without undefined behavior
Downloads
6
Maintainers
Readme
aasy
Async - easy.
Zero-library Promise wrapper without pain.
Make Promise without undefined behavior(almost).
Reason to use aasy
- Typescript types. Promise stantard generic is not accepts Reject generic. aasy does.
- Less undefined behavior, when using safe function.
- Inherited from built-in Promise object
- 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>
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