0.1.0 • Published 6 years ago

promout v0.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

promout

return a promise what is resolved after timeout milliseconds

Usage

// resolve
const res = {};
const init = Date.now();
const _res = await promout(res, 2000);
const finish = Date.now();
assert(finish - init > 2000);
assert(_res === res);
// without res
const init = Date.now();
const _res = await promout(2000);
const finish = Date.now();
assert(finish - init > 2000);
assert(_res === 2000);
// with reject
const res = {};
const init = Date.now();
const _res = await promout.reject(res, 2000).catch((res) => res);
const finish = Date.now();
assert(finish - init > 2000);
assert(_res === res);

// without res
// with reject
const init = Date.now();
const _res = await promout.reject(2000).catch((res) => res);
const finish = Date.now();
assert(finish - init > 2000);
assert(_res === 2000);

API

promout(res, timeout=0) -> Promise

The promise is resolved with res given at timeout milliseconds.

promout.reject(res, timeout=0) -> Promiserejected

The promise is rejected with res given at timeout milliseconds.