Files
wren/cli/modules/scheduler/scheduler.html
2021-02-06 15:58:10 +00:00

99 lines
3.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Scheduler Class &ndash; Wren</title>
<script type="application/javascript" src="../../../prism.js" data-manual></script>
<script type="application/javascript" src="../../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../../prism.css" />
<link rel="stylesheet" type="text/css" href="../../../style.css" />
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic,700italic|Source+Code+Pro:400|Lato:400|Sanchez:400italic,400' rel='stylesheet' type='text/css'>
<!-- Tell mobile browsers we're optimized for them and they don't need to crop
the viewport. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
</head>
<body id="top" class="module">
<header>
<div class="page">
<div class="main-column">
<h1><a href="../../../">wren</a></h1>
<h2>a classy little scripting language</h2>
</div>
</div>
</header>
<div class="page">
<nav class="big">
<a href="../../../"><img src="../../../wren.svg" class="logo"></a>
<ul>
<li><a href="../../">Back to Wren CLI</a></li>
<li><a href="../">Back to CLI Modules</a></li>
<li><a href="./">scheduler module</a></li>
</ul>
<section>
<h2>scheduler classes</h2>
<ul>
<li><a href="scheduler.html">Scheduler</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><a href="../">Back to CLI Modules</a></td>
<td><a href="./">scheduler module</a></td>
</tr>
<tr>
<td colspan="2"><h2>scheduler classes</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="scheduler.html">Scheduler</a></li>
</ul>
</td>
<td>
<ul>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>Scheduler Class</h1>
<p>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 <em>long running</em> methods in the File or Timer classes which suspend the current fiber so that Wren can carry out other tasks in the meantime.</p>
<h2>Static Method <a href="#static-method" name="static-method" class="header-anchor">#</a></h2>
<h3>Scheduler.<strong>add</strong>(callable) <a href="#scheduler.add(callable)" name="scheduler.add(callable)" class="header-anchor">#</a></h3>
<p>Adds a new fiber to the scheduler&rsquo;s fibers list. This fiber calls <code>callable</code> and then transfers to the next fiber in the list, if there is one.</p>
<p><code>callable</code> is a function or other object which has a call() method.</p>
<pre class="snippet">
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
</pre>
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/main/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>