@harexs/pack-await
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@harexs/pack-await

Don't need use try..catch, Promise to package await results

Install

$ npm install @harexs/pack-await

Usage

import pAwait from "@harexs/pack-await";

const p1 = () => Promise.reject("harexs");
const [res, err] = pAwait(p1()); // [null,'harexs']

const p2 = () => Promise.resolve({ code: 200, msg: "OK", data: [] });
const [res, err] = pAwait(p1()); // [{code:200,msg:'OK',data:[]},null]

//use errObj
const p3 = () => Promise.resolve({ code: 200, msg: "OK", data: [] });
const [res, err] = pAwait(p3(), { msg: "change msg" }); // [{code:200,msg:'change msg',data:[]},null]

Readme

Keywords

none

Package Sidebar

Install

npm i @harexs/pack-await

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

3.57 kB

Total Files

6

Last publish

Collaborators

  • gu1st