Last active
August 29, 2015 14:00
-
-
Save Deltachaos/11343562 to your computer and use it in GitHub Desktop.
This file contains 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
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