Lazy Promise creates native Promise only if you use then
or catch
methods.
npm i --save @perf-tools/promise
import { LazyPromise } from '@perf-tools/promise';
const lazy = new LazyPromise((resolve) => {
resolve('LAZY!');
});
console.log('Like native:', lazy instanceof Promise); // Like native: true
console.log('Lazy?', lazy instanceof LazyPromise); // Lazy? true
// Activation (create Native Promise)
lazy.then((val) => {
console.log('result:', val); // result: LAZY!
});
npm i
npm test
, code coverage