File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ The `run` method activates the scheduler. The scheduler resumes all coroutines a
1515``` pluto
1616local scheduler = new (require"pluto:scheduler") ()
1717
18+ -- Make this example behave a bit better in the non-blocking WASM environment
19+ if coroutine.isyieldable() then
20+ scheduler.yieldfunc = || -> coroutine.sleep(1)
21+ end
22+
1823local loops = 0
1924scheduler:addloop(function()
2025 ++loops
@@ -50,8 +55,8 @@ scheduler:run()
5055``` pluto
5156local scheduler = new (require"pluto:scheduler") ()
5257
53- -- Yield to OS every second instead of every millisecond .
54- scheduler.yieldfunc = || -> os .sleep(1000)
58+ -- Use coroutine.sleep instead of os.sleep in a non-blocking environment, and increase the timeout from 1 to 1000 ms (1 second) .
59+ scheduler.yieldfunc = || -> (coroutine.isyieldable() ? coroutine : os) .sleep(1000)
5560
5661local loops = 0
5762scheduler:addloop(function()
You can’t perform that action at this time.
0 commit comments