Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@extra-js/deferred

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@extra-js/deferred

A simple wrapper around Promise API to programmatically trigger resolution or rejection

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Deferrable Promises (Deferred)

A simple promise-like object which exposes resolve and reject methods.

Resolve

import assert from 'assert';
import { Deferred } from '@extra-js/deferred';

process.on('unhandledRejection', (error) => {
  throw error;
});

async function main() {
  const future: Deferred<string> = new Deferred<string>();
  setTimeout(future.resolve.bind(future, 'foo'));
  const val = await future;
  assert(val === 'foo', 'operation should be resolved');
}

main.call(this);

Reject

import assert from 'assert';
import { Deferred } from '@extra-js/deferred';

process.on('unhandledRejection', (error) => {
  throw error;
});

async function main() {
  const future: Deferred<string> = new Deferred<string>();
  setTimeout(future.reject.bind(future, new Error('foo')));
  try {
    await future;
  } catch (error) {
    assert(error.message === 'foo');
  }
}

main.call(this);

Timeout

import assert from 'assert';
import { Deferred } from '@extra-js/deferred';

process.on('unhandledRejection', (error) => {
  throw error;
});

async function main() {
  const TIMEOUT = 1000; // 1s
  const future: Deferred<string> = new Deferred<string>(TIMEOUT);
  try {
    await future;
  } catch (error) {
    assert(error.message === 'Timeout');
  }
}

main.call(this);

Keywords

FAQs

Package last updated on 13 Jun 2019

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc