Created
August 15, 2016 17:23
-
-
Save jonasfj/959b5148e0d1fdf081fb1304a1740969 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Iterate = require(`./`); | |
// Define a poller operation using Iterate | |
let Poller = Iterate({ | |
maxIterations: 0, | |
maxFailures: 7, | |
maxIterationTime: 45 * 1000, | |
minIterationTime: 0, | |
watchDog: 30 * 1000, | |
waitTime: 500, | |
waitTimeAfterFail: 1000, | |
parallelism: 1, // number of handlers to loops to run concurrently | |
context: ['state', 'url'], | |
handler(watchdog) { | |
await someMethodThatPolls(this.url); | |
watchdog.touch(); | |
this.state += 1; // Modify the state | |
}, | |
}); | |
// Create an instance of poller | |
let poller = new Poller({ | |
// Provide monitor, dmsConfig and context | |
monitor: ..., | |
dmsConfig: {...}, | |
context: { | |
state: 0, | |
url: '...', | |
}, | |
// Overwrite pre-defined settings (optional) | |
maxIterations: 0, | |
maxFailures: 7, | |
maxIterationTime: 45 * 1000, | |
minIterationTime: 0, | |
watchDog: 30 * 1000, | |
waitTime: 500, | |
waitTimeAfterFail: 1000, | |
parallelism: 1, | |
}); | |
// Run a single iteration (useful for testing) | |
await poller.singleIteration() | |
// Start running iterations | |
poller.start() | |
// Stop polling, will wait for currently iteration(s) to be done | |
await poller.stop() | |
// Wait for poller to be stopped, throw an error, or maxIterations to be reached | |
poller.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment