Socket
Socket
Sign inDemoInstall

@nodesuite/defer

Package Overview
Dependencies
1
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @nodesuite/defer

Deferred Promise resolution tools.


Version published
Maintainers
1
Created

Readme

Source
nodesuite

@nodesuite/defer

Summary

Simple deferred Promise generator.

Installation

pnpm install @nodesuite/defer

Usage

import { defer } from "@nodesuite/defer"

import { someEventfulEmitter } from "./events"

const { resolve, reject, untilResolved } = defer()


// Define async work...
someEventfulEmitter.on("someEvent", resolve)

// ...or some alternative trigger...
const secondEmitter = new EventEmitter()
secondEmitter.on("secondEvent", resolve)

// ...or abstract resoltion conditons...
class Foo {
	
  #resolve
	#reject
  
	public constructor({ resolve, reject }) {
    this.#resolve = resolve
		this.#reject = reject
	}
  
  public someSuccessFunction() {
    return this.#resolve()
	}
  
  public someFailureFunction() {
    return this.#reject()
	}
  
}

const foo = new Foo({ resolve, reject })

// Reject the master promise...
someEventfulEmitter.on("error", () => foo.someFailureFunction())

// Can await resolution of promise from any source.
await untilResolved()



Keywords

FAQs

Last updated on 02 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc