Skip to content

immafrady/polling-machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polling-machine

A easy way to use polling

  • Promise
  • ES6 Class

So you might need to use Babel alongside with it.

Installation

npm install -S polling-machine

Usage

1. create new instance

    const pollingMachine = new PollingMachine(aPromiseMethod, arg1, arg2, /* and so on */)

2. add event listener

    // event name must be one of 'message' and 'error'
    pollingMachine.on('message', res => /* something to do with response */)
    pollingMachine.on('error', err => /* something to do with error */)

3. start polling

    pollingMachine.start() // default time gap is 5000ms,
    // or
    pollingMachine.start(10000)

4. stop polling

    pollingMachine.stop()

5. restart polling

    pollingMachine.stop() // you need to stop polling before restart it, or an error will be thrown.
    pollingMachine.start()

License

MIT

About

A easy way to use polling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published