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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jcoreio/poll

v3.0.1

Published

handy promised-based polling API

Downloads

4,873

Readme

poll

Build Status Coverage Status semantic-release Commitizen friendly

yet another promise-based poller (I didn't like the API design of others out there)

Example

npm install --save @jcoreio/poll
const poll = require('@jcoreio/poll')
const superagent = require('superagent')

poll(() => superagent.get('http://google.com'), 1000)
  .timeout(30000)
  .then(() => console.log("You're connected to the internet!"))

poll(fn, interval, [options])

Begins calling fn every interval milliseconds until the condition passes (which defaults to fn didn't throw an Error or return a rejected Promise).

Returns a Promise that resolves when polling finishes or fails, which may be:

  • when fn calls the pass method provided to it
  • when fn calls the fail method provided to it
  • when fn returns/resolves to a value or throws/rejects with an Error that passes the condition
  • when a timeout is specified and poll times out waiting for any of the above

fn will be called with a context object:

{
  attemptNumber: number, // the number of this call (starting from 0)
  elapsedTime: number, // the number of milliseconds since polling started
  pass: (value: any) => void, // makes `poll` resolve immediately with this value
  fail: (error: Error) => void, // makes `poll` reject immediately with this Error
}

You can change the condition by calling .until on the returned Promise:

poll(...).until((error, result) => result > 3)

error will be the Error from the last call to fn (if it rejected or threw) and result will be the value it resolved to or returned otherwise.

You can specify a timeout (in milliseconds) by calling .timeout on the returned Promise:

poll(...).timeout(30000) // time out after 30 seconds

If you call .noWrapError() on the returned Promise, it won't wrap rejection errors.