From 16ddbb66f8d7a83b2f3c2aee0360fad6701dc419 Mon Sep 17 00:00:00 2001 From: PureFox48 <64583745+PureFox48@users.noreply.github.com> Date: Sun, 31 Jan 2021 05:15:56 +0000 Subject: [PATCH] Add docs for Scheduler class (#902) I think it's time we had a go at this. --- .../cli/modules/scheduler/scheduler.markdown | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/site/cli/modules/scheduler/scheduler.markdown b/doc/site/cli/modules/scheduler/scheduler.markdown index cf6caa3c..1fe5cc5b 100644 --- a/doc/site/cli/modules/scheduler/scheduler.markdown +++ b/doc/site/cli/modules/scheduler/scheduler.markdown @@ -1,7 +1,27 @@ ^title Scheduler Class -**TODO** +The Scheduler class maintains a list of fibers, to be started one after the other, when a signal to do so is received. The signal (a private method call) is typically transmitted by _long running_ methods in the File or Timer classes which suspend the current fiber so that Wren can carry out other tasks in the meantime. -## Methods +## Static Method -**TODO** +### Scheduler.**add**(callable) + +Adds a new fiber to the scheduler's fibers list. This fiber calls `callable` and then transfers to the next fiber in the list, if there is one. + +`callable` is a function or other object which has a call() method. + +
+var a = 3
+
+Scheduler.add {
+  a = a * a
+}
+
+Scheduler.add {
+  a = a + 1
+}
+
+System.print(a)        // still 3
+Timer.sleep(3000)      // wait 3 seconds
+System.print(a)        // now 3 * 3 + 1 = 10
+