I have a long running process which will sit and poll a REST API for a status change. Traditionally, I had just created a Runnable instance and fed it to a Java Thread, but thought I might look into Ringo's Worker and WorkerPromise api.
So my Worker module will have an onmessage() handler to receive some control messages which will tell the polling loop whether to start, stop, shutdown. So a WorkerPromise is out for me as it has a one-time use syntax. I have other types of workers where WorkerPromise will work nicely.
But, my worker that polls does not look like it will fit well in the Worker or WorkerPromise world. At some point in the operation of this Worker I need a loop that functions like this:
function poll() {
while (notShutdown) {
while (isPolling) {
<do the polling work>
}
java.lang.Thread.sleep(1000);
}
}
Is this just a bad fit for the Worker, or is there a technique that I am missing?