Socket
Socket
Sign inDemoInstall

@esutils/deferred

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esutils/deferred


Version published
Weekly downloads
1.2K
increased by15.49%
Maintainers
1
Install size
11.2 kB
Created
Weekly downloads
 

Readme

Source

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();

Keywords

FAQs

Last updated on 13 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc