Socket
Socket
Sign inDemoInstall

node-threading-event

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-threading-event

An implementation of the threading.Event Python package


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

node-threading-event

A simple and lightweight implementation of threading.Event in Node.js

Installation

Node.js 15.0.0 or newer is required.

npm install node-threading-event

Example usage

const NodeThreadingEvent = require('node-threading-event');

const event = new NodeThreadingEvent();

event.set();

if (event.isSet()) {
  console.log('Event is set !');
}

event.clear();

(async function() {
  setTimeout(() => {
    event.set();
  }, 1000);

  const res = await event.wait();
  console.log('Event is set after 1 second');
})()

(async function() {
  setTimeout(() => {
    event.set();
  }, 500);

  const res = await event.wait(1000);
  console.log('Event is set after 1 second');
})()

Documentation

set()

Set the internal flag to true.

  • Return void

isSet()

Return true if and only if the internal flag is true.

  • Return boolean

clear()

Reset the internal flag to false.

  • Return void

wait(timeout = null)

Block until the internal flag is true.

If the internal flag is true on entry, return immediately. Otherwise, block until another set() call to set the flag to true, or until the optional timeout occurs.

  • timeout - (optional) - Specify the time to wait until the timeout occurs.
  • Return Promise<boolean>

Keywords

FAQs

Last updated on 20 Aug 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