mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
// Generated automatically from src/module/timer.wren. Do not edit.
|
|
static const char* timerModuleSource =
|
|
"class Timer {\n"
|
|
" static sleep(milliseconds) {\n"
|
|
" if (!(milliseconds is Num)) Fiber.abort(\"Milliseconds must be a number.\")\n"
|
|
" if (milliseconds < 0) Fiber.abort(\"Milliseconds cannot be negative.\")\n"
|
|
" startTimer_(milliseconds, Fiber.current)\n"
|
|
"\n"
|
|
" runNextScheduled_()\n"
|
|
" }\n"
|
|
"\n"
|
|
" // TODO: Once the CLI modules are more fleshed out, find a better place to\n"
|
|
" // put this.\n"
|
|
" static schedule(callable) {\n"
|
|
" if (__scheduled == null) __scheduled = []\n"
|
|
" __scheduled.add(Fiber.new {\n"
|
|
" callable.call()\n"
|
|
" runNextScheduled_()\n"
|
|
" })\n"
|
|
" }\n"
|
|
"\n"
|
|
" foreign static startTimer_(milliseconds, fiber)\n"
|
|
"\n"
|
|
" // Called by native code.\n"
|
|
" static resumeTimer_(fiber) {\n"
|
|
" fiber.transfer()\n"
|
|
" }\n"
|
|
"\n"
|
|
" static runNextScheduled_() {\n"
|
|
" if (__scheduled == null || __scheduled.isEmpty) {\n"
|
|
" Fiber.suspend()\n"
|
|
" } else {\n"
|
|
" __scheduled.removeAt(0).transfer()\n"
|
|
" }\n"
|
|
" }\n"
|
|
"}\n";
|