npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

pollsky

v1.2.0

Published

Chained Polling Library for Node.js: Friendly API with no external dependencies.

Downloads

2,093

Readme

Pollsky

⛓ Chained Polling Library for Node.js

  • 💪 Strongly typed
  • 🧩 No dependencies
  • 👓 Human-readable syntax

What makes Pollsky different?

Just as other Node.js libraries of this purpose, Pollsky is built on top of promises, but the unique feature of this package is an almost English-like interface. Instead of:

  import 'otherPoller';

  const taskFn = async () => { /** Do something... */ };

  otherPoller({
    taskFn,
    interval: 500,
    timeout: 5000
    // Other options... 
  });

you can achieve the same effect with this syntax:

  import { poll } from 'pollsky';

  const taskFn = async () => { /** Does something and returns a string */ };

  const conditionFn = value => value === 'foo';

  const poll(taskFn).atMost(5000, 'milliseconds').withInterval(500, 'milliseconds').until(conditionFn);

Installation

Using npm:

  $ npm install pollsky

Using yarn:

  $ yarn add pollsky

Usage

The simpliest use case:

  poll(waitForSomething).until(checkCondition);

where waitForSomething is an async function to keep executing and checkCondition - a function that checks if polling has ended successfully.

By default Pollsky does not call timeout and is being executed without the end. If you want to change this behaviour you can define a timeout like this:

  // In seconds...
  poll(waitForSomething).atMost(20, 'seconds').until(checkCondition);

  // ...and in milliseconds if you like
  poll(waitForSomething).atMost(500, 'milliseconds').until(checkCondition);

Using withInterval() we can change the polling interval:

  poll(waitForSomething).withInterval(5, 'seconds').until(checkCondition);

  // We can easily chain methods however we want
  poll(waitForSomething).withInterval(5, 'seconds').atMost(2, 'minutes').until(checkCondition);

It's sometimes useful to ignore exceptions during condition evaluation.

  poll(waitForSomething).ignoreErrors().until(checkCondition);

You can instruct Pollsky to wait a certain amount of time

  poll(waitForSomething).atMost(30, 'seconds').until(checkCondition);

If we don't want Pollsky to throw when polling fails we can use dontThrowError() to return the last result

  poll(waitForSomething).dontThrowError().until(conditionThatFails);

Debugging

  1. Enable debug logging - set an environment variable DEBUG=pollsky to enable extra logging
  # Enabling debug logging
  $ DEBUG=pollsky node script.js
  1. Error's failures object - an error thrown on failure includes property failures that contains history of thrown errors
  try {
    await poll(async () => 'foo')
      .returnValueIfFailed()
      .atMost(1000, 'milliseconds')
      .until(result => result === 'bar');
  } catch(error) {
    console.log(error.failures);
    // Output:
    // [
    //     {
    //       error: 'ConditionFunctionError',
    //       errorMsg: 'Condition is not met - function `conditionFn() returned `false` instead of `true`.',
    //       result: 'foo',
    //       timestamp: '2021-10-09T16:11:56.925Z'
    //     },
    //     {
    //       error: 'AtMostConditionError',
    //       errorMsg: 'Timeout has called before condition is met.',
    //       result: 'foo',
    //       timestamp: '2021-10-09T16:11:57.927Z'
    //     }
    //   ]
  }

Roadmap

[X] Allow returning a result even if polling failed [X] Extend error object to contain failures history [] Allow initialising custom Pollsky object with predefined options [] Implement increasing interval strategies, fibonacci sequence et al. [] Add event emitter

Credits

Pollsky is heavily inspired by the Awaitility . Thank you for great Java library.

License

MIT