deferred
library that written in typescript
A minimal This deferred library can be used by es
module, commonjs
module and typescript
module
Examples
es
module, file with .mjs
or .js
extension
Usage in When .js
extension used, the value of module
property in package.json
should be module
.
import { Deferred } from '@esutils/deferred';
async function demo() {
const defer = new Deferred();
setTimeout(() => {
defer.resolve();
});
console.log(`Start ${Date.now()}`);
await defer.promise;
console.log(`End ${Date.now()}`);
}
demo();
commonjs
module, file with .cjs
or .js
extension
Usage in When .js
extension used, the value of module
property in package.json
should be commonjs
or not specified.
const { Deferred } = require('@esutils/deferred');
async function demo() {
const defer = new Deferred();
setTimeout(() => {
defer.resolve();
});
console.log(`Start ${Date.now()}`);
await defer.promise;
console.log(`End ${Date.now()}`);
}
demo();
typescript
module, file with .ts
extension
Usage in import { Deferred } from '@esutils/deferred';
async function demo() {
const defer = new Deferred<void>();
setTimeout(() => {
defer.resolve();
});
console.log(`Start ${Date.now()}`);
await defer.promise;
console.log(`End ${Date.now()}`);
}
demo();