Events: Difference between revisions
Content added Content deleted
(Replaced "cpuTime" by "getTime" to get elapsed time and take sleeping time in account.) |
(Added Wren) |
||
Line 1,205: | Line 1,205: | ||
vwait X |
vwait X |
||
puts "received event"</lang> |
puts "received event"</lang> |
||
=={{header|Wren}}== |
|||
Wren-cli supports the scheduling of tasks using a timer. |
|||
The tasks to be executed are added to a list by the Scheduler class. The Timer.sleep method suspends the current fiber and signals the scheduler (by calling a private method) to execute the tasks one by one in their own fibers - in Wren only one fiber can execute at a time. The task results are then available to the main fiber on its resumption after Timer.sleep has completed. |
|||
<lang ecmascript>import "scheduler" for Scheduler |
|||
import "timer" for Timer |
|||
var a = 3 |
|||
// add a task |
|||
Scheduler.add { |
|||
a = a * a |
|||
} |
|||
// add another task |
|||
Scheduler.add { |
|||
a = a + 1 |
|||
} |
|||
System.print(a) // still 3 |
|||
Timer.sleep(3000) // wait 3 seconds |
|||
System.print(a) // now 3 * 3 + 1 = 10</lang> |
|||
{{out}} |
|||
<pre> |
|||
3 |
|||
10 |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |