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

jdefer

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jdefer

# Install

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

Javascript promise defer library

Install

yarn add jdefer

Usage

Single promise with defer

In 2024: recommended using Promise.withResolvers().

import makeDefer from 'jdefer'
// or
const makeDefer = require('jdefer')

const defer = makeDefer()

// to reject
defer.reject(new Error('foo'))

// to resolve
defer.resolve('bar')

// to wait
await defer.promise

Broadcast stream

import {makeBroadcastStream} from 'jdefer'
// or
const {makeBroadcastStream} = require('jdefer')

const stream = makeBroadcastStream()

// to listen
const removeListener = stream.listen(
	(value) => {
		console.log(value)
	}, {
		onDone() {
			console.log('done')
		},
		onError(error) {
			console.error(error)
		},
	})

// to stop listening
removeListener()

// to broadcast
stream.next('foo')
// to broadcast error
stream.throw(new Error('bar'))
// to broadcast done
stream.done()
// iterate
for await (const value of stream) {
	console.log(value)
}

Keywords

FAQs

Package last updated on 06 Nov 2024

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