@esutils/deferred
v0.1.2
Published
The deferred library implemented in Typescript
Downloads
5,951
Maintainers
Readme
A minimal deferred
library that written in typescript
This deferred library can be used by es
module, commonjs
module and typescript
module
Examples
Usage in es
module, file with .mjs
or .js
extension
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();
Usage in commonjs
module, file with .cjs
or .js
extension
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();
Usage in typescript
module, file with .ts
extension
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();