William Bradee
Posts: 0
Joined: Thu Oct 03, 2013 8:45 pm

Server Code Sleep/Wait

I have a service that is waiting for a response from another service that I have to poll.

Is there a sleep/wait command, e.g. just to sleep for a second?

I want to write a poll loop like pseudo code:

do {
request status
if status is OK {
break;
}
if timeout {
break
}
sleep for 1 second
} while true // forever

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Server Code Sleep/Wait

Hi William,

Try the following function:prefunction sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date()&#46;getTime() - start) milliseconds){
break;
}
}
}/pre
To call it run:presleep(1000);/preThe delay equals 1 second.

William Bradee
Posts: 0
Joined: Thu Oct 03, 2013 8:45 pm

Server Code Sleep/Wait

Thanks, but I don't want to put a spin loop on a server ...

tried sleep, delay, wait, timeout, setTimeout -- they're not supported.

I thought mayb since REST calls are blocking you might have a blocking call to wait.

I could always put the polling on the client, but it would be cleaner to do on the server.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Server Code Sleep/Wait

William,

This won't work on server. You would need to implement this on client side.

Return to “Issues”