Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Find another method to create a thread sleep #3

Open
adamheinmiller opened this issue Jun 3, 2014 · 2 comments
Open

Find another method to create a thread sleep #3

adamheinmiller opened this issue Jun 3, 2014 · 2 comments
Assignees

Comments

@adamheinmiller
Copy link
Owner

Tested a method using HTTP GET timeouts, but that provides a hard 10-second sleep and is too long of a delay. I wasn't able to find a way to change the timeout.

@steveganz
Copy link

@sepiroth887
Copy link

i stumbled over that and also recent issues with poll() in smartthings itself.

The solution I came up with is actually pretty close in timing things correctly :

def sleepForDuration(duration, callback = {})
{
// I'm sorry!

def dTotalSleep = 0
def dStart = new Date().getTime()

while (dTotalSleep <= duration)
{            
    try { httpGet("http://deelay.me/$duration/http://www.google.com ") { } } catch (e) { }

    dTotalSleep = (new Date().getTime() - dStart)
}

log.debug "Slept ${dTotalSleep}ms"

callback(dTotalSleep)

}

the deelay.me is a page that allows to simulate how bad latency can be and basically waits to load the page until the $duration has expired and then invokes the next URL passed (google.com) the cool thing about it is that google.com is rather fast from anywhere in the world thanks to global loadbalancing which means timings are pretty solid.

I made another few changes too i can probably create a PR for it, it's now working reliably and more importantly TIMELY! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants