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

signal-promise

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signal-promise - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

24

index.js

@@ -7,6 +7,11 @@ module.exports = class Signal {

this._bind = bind.bind(this)
this._clear = clear.bind(this)
this._timers = new Set()
}
wait (max) {
if (!this._promise) this._promise = new Promise(this._bind)
if (!this._promise) {
this._promise = new Promise(this._bind)
this._promise.then(this._clear).catch(this._clear)
}
if (max) return this._sleep(this._promise, max)

@@ -17,11 +22,11 @@ return this._promise

_sleep (p, max) {
let id
const clear = () => clearTimeout(id)
const s = new Promise(resolve => {
id = setTimeout(resolve, max, true)
const done = () => {
this._timers.delete(id)
resolve(true)
}
const id = setTimeout(done, max)
this._timers.add(id)
})
p.then(clear).catch(clear)
p.catch(clear)
return Promise.race([s, p])

@@ -40,2 +45,7 @@ }

function clear () {
for (const id of this._timers) clearTimeout(id)
this._timers.clear()
}
function bind (resolve, reject) {

@@ -42,0 +52,0 @@ this._resolve = resolve

{
"name": "signal-promise",
"version": "1.0.1",
"version": "1.0.2",
"description": "Simple wait/notify promise with optional max wait time",

@@ -5,0 +5,0 @@ "main": "index.js",

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