Skip to content

Instantly share code, notes, and snippets.

@Deltachaos
Last active August 29, 2015 14:00
Show Gist options
  • Save Deltachaos/11343562 to your computer and use it in GitHub Desktop.
Save Deltachaos/11343562 to your computer and use it in GitHub Desktop.
package ;
import js.Node;
@:coreApi class Sys
{
public static function sleep( seconds : Float ) : Void {
#if nodejsSleepFallback
var stopTime : Float = time() + seconds;
#end
if (_sleep != null) {
untyped _sleep.usleep(seconds * 1000000);
} else {
#if nodejsSleepFallback
// It is relay frustrading that there is no other soulution to this in nodejs
while (time() < stopTime) {}
#else
throw "sleep Module not available. Please install https://www.npmjs.org/package/sleep or pass nodejsSleepFallback as compiler flag to fallback to an while loop which will use 100% CPU!";
#end
}
}
public static function __init__() : Void {
try {
_sleep = untyped __js__("require('sleep')");
} catch(e : Dynamic) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment