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

@open-draft/deferred-promise

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-draft/deferred-promise

A Promise that can be resolved/rejected elsewhere

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @open-draft/deferred-promise?

@open-draft/deferred-promise is a utility library that provides a way to create and manage deferred promises. This can be particularly useful in scenarios where you need to create a promise and resolve or reject it at a later time, outside of the initial promise executor function.

What are @open-draft/deferred-promise's main functionalities?

Creating a Deferred Promise

This feature allows you to create a deferred promise that can be resolved or rejected at a later time. The code sample demonstrates creating a deferred promise, resolving it after a timeout, and then using the promise in an async function.

const { DeferredPromise } = require('@open-draft/deferred-promise');

const deferred = new DeferredPromise();

// You can resolve or reject the promise later
setTimeout(() => {
  deferred.resolve('Resolved value');
}, 1000);

// Use the promise
async function main() {
  const result = await deferred;
  console.log(result); // 'Resolved value'
}

main();

Handling Rejection

This feature allows you to handle the rejection of a deferred promise. The code sample demonstrates creating a deferred promise, rejecting it after a timeout, and then handling the rejection in an async function.

const { DeferredPromise } = require('@open-draft/deferred-promise');

const deferred = new DeferredPromise();

// You can resolve or reject the promise later
setTimeout(() => {
  deferred.reject(new Error('Something went wrong'));
}, 1000);

// Use the promise
async function main() {
  try {
    const result = await deferred;
  } catch (error) {
    console.error(error.message); // 'Something went wrong'
  }
}

main();

Other packages similar to @open-draft/deferred-promise

Keywords

FAQs

Package last updated on 20 Oct 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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc