Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
A simple poll function based on async, await, and an infinite loop.
Links:
Download the ES module file …
curl -O https://raw.githubusercontent.com/kleinfreund/poll/main/dist/esm/poll.mjs
… and import it like this:
import poll from 'poll.mjs';
function fn() {
console.log('Hello, beautiful!');
};
poll(fn, 1000);
Install the node package as a dependency …
npm install --save poll
… and import it like this:
CommonJS module
const poll = require('poll').default;
function fn() {
console.log('Hello, beautiful!');
};
poll(fn, 1000);
ES module
import poll from 'poll/dist/esm/poll.mjs';
function fn() {
console.log('Hello, beautiful!');
};
poll(fn, 1000);
TypeScript module
import poll from 'poll/src/poll';
function fn() {
console.log('Hello, beautiful!');
};
poll(fn, 1000);
In order to run the tests, clone the repository and run the following commands:
npm install
npm test
poll(function, delay[, shouldStopPolling])
Parameters:
function: Required. A function to be called every delay
milliseconds. No parameters are passed to function
upon calling it.
delay: Required. The delay (in milliseconds) to wait before calling the function again.
shouldStopPolling: Optional. A function indicating whether to stop the polling process. The callback function is evaluated twice during one iteration of the internal loop:
function
was successfully awaited. In other words, right before triggering a new delay period.delay
has passed. In other words, right before calling function
again.This guarantees two things:
function
will be completed.function
will be triggered.Return value:
None.
1.0.0 (2019-08-04)
Importing the CommonJS module with require('poll')
no longer resolves to the poll
function. Use require('poll').default
instead.
const poll = require('poll').default;
Non-breaking changes:
The package is now available as an ES module. If you use poll
as a dependency, import it like this:
import poll from 'poll/dist/esm/poll.mjs';
Tests now use Jest instead of Ava.
Tests are now based on fake timers instead of calling setTimeout
in the tests directly. Unfortunately, tests still require a lot of trickery to manually clear out the promise queue. If you know how to test this without sprinkling await Promise.resolve()
all over my tests, I’m all ears!
FAQs
A simple poll function based on async, await, and an infinite loop
The npm package poll receives a total of 2,190 weekly downloads. As such, poll popularity was classified as popular.
We found that poll demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.