Fixed issue: #71
This commit is contained in:
BIN
examples/jse/SampleLuaScheduler.class
Normal file
BIN
examples/jse/SampleLuaScheduler.class
Normal file
Binary file not shown.
31
examples/jse/SampleLuaScheduler.java
Normal file
31
examples/jse/SampleLuaScheduler.java
Normal file
@@ -0,0 +1,31 @@
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.libs.jse.JsePlatform;
|
||||
import org.luaj.vm2.libs.jse.LuaScheduler;
|
||||
|
||||
public class SampleLuaScheduler {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
LuaScheduler scheduler = new LuaScheduler(globals);
|
||||
|
||||
globals.load(
|
||||
"spawn(function()\n" +
|
||||
" print('task1 start')\n" +
|
||||
" wait(250)\n" +
|
||||
" print('task1 after wait')\n" +
|
||||
"end)\n" +
|
||||
"spawn(function()\n" +
|
||||
" print('task2 start')\n" +
|
||||
" yield()\n" +
|
||||
" print('task2 next tick')\n" +
|
||||
"end)\n",
|
||||
"sample_scheduler.lua"
|
||||
).call();
|
||||
|
||||
while (scheduler.hasPendingTasks()) {
|
||||
if (scheduler.runReadyTasks() == 0) {
|
||||
Thread.sleep(scheduler.millisUntilNextTask());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user