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

awty

v0.1.0

Published

"Are we there yet?", a timeout/interval utility for polling.

Downloads

666

Readme

awty

awty, Are We There Yet?, is a simplistic polling module for repeat checking on asynchrous tasks.

Build Status

Example

var awty = require('awty');
var poll = awty(function() {
  // perform check on a certain length task
  // return true if and when finished polling
});

poll(function() {
  console.log('finished polling');
});

Installation

Node

To install awty in a Node application use npm.

$ npm install awty

Browser

No tests available for the browser but you may try using it via webpack.

$ webpack index.js awty.js

Test

To run tests use npm.

$ npm install
$ npm test

Documentation

Basic Usage

awty takes a callback that will be called on each poll. Simply return true whenever the polling is finished. To start polling call the returned instance supplying a done callback.

poll.every(250) // every 250ms
    .ask(5);    // only poll check 5 times

// start polling
poll(function(fin) {
  if (fin) console.log('polling finished');
  else console.log('polling stopped unfinished');
});

Set the timeout for each poll by the every method, passing a number of ms each call should wait.

A poll limit can also be set by the ask method, just pass a maximum number the poll should call.

Async Usage

The callback that awty takes is also provided a next function as an argument. If the function uses the argument, it will wait until the next function is called.

Instead of returning, whether or not to stop needs to be provided as an argument to the next function.

var awty = require('awty');
var poll = awty(function(next) {
  setTimeout(function() {
    next(/* `true` if polling should be finished */);
  }, 100)
});

poll(function() {
  console.log('finished polling');
});

Incremental Polls

It possible to increment the timeout after each poll, using the incr method it will double the last timeout. Or supplying an number of ms to increment by.

poll.incr(); // 250, 500, 1000, 2000, 4000, ...

// or set ms

poll.incr(50); // 250, 300, 350, 400, 450, ...

API

awty(<poll>)

poll(<cb>)

poll.every(<ms>)

poll.ask(<num>)

poll.incr(<val>)

License

MIT

Copyright (c) 2014 Christopher Turner