1.0.1 • Published 10 months ago

@harexs/pack-await v1.0.1

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

@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]
1.0.1

10 months ago

1.0.0

10 months ago