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

poll

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poll

A simple poll function based on async, await, and an infinite loop

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4K
decreased by-12.39%
Maintainers
1
Weekly downloads
 
Created
Source

poll

A simple poll function based on async, await, and an infinite loop.

Links:

  • npmjs.com/package/poll
  • github.com/kleinfreund/poll

Table of contents

Installation

Browser

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);

Node

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);
    

Tests

In order to run the tests, clone the repository and run the following commands:

npm install
npm test

Documentation

Syntax

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:

    • After the result of the call to function was successfully awaited. In other words, right before triggering a new delay period.
    • After the delay has passed. In other words, right before calling function again.

    This guarantees two things:

    • A currently active execution of function will be completed.
    • No new calls to function will be triggered.

Return value:

None.

Keywords

FAQs

Package last updated on 04 Aug 2019

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