A easy way to use polling
- Promise
- ES6 Class
So you might need to use Babel alongside with it.
npm install -S polling-machine
const pollingMachine = new PollingMachine(aPromiseMethod, arg1, arg2, /* and so on */) // 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 */) pollingMachine.start() // default time gap is 5000ms,
// or
pollingMachine.start(10000) pollingMachine.stop() pollingMachine.stop() // you need to stop polling before restart it, or an error will be thrown.
pollingMachine.start()