awty
awty
, Are We There Yet?, is a simplistic polling module for repeat checking on asynchrous tasks.
Example
var awty = ;var poll = ; ;
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 250ms ; // only poll check 5 times // start polling;
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 = ;var poll = ; ;
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; // 250, 500, 1000, 2000, 4000, ... // or set ms poll; // 250, 300, 350, 400, 450, ...
API
awty(<poll>)
poll(<cb>)
poll.every(<ms>)
poll.ask(<num>)
poll.incr(<val>)
License
Copyright (c) 2014 Christopher Turner