1
0
Fork 0
cl-sites/guile.html_node/Cooperative-REPL-Servers.html
2024-12-17 12:49:28 +01:00

111 lines
5.6 KiB
HTML

<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This manual documents Guile version 3.0.10.
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
Inc.
Copyright (C) 2021 Maxime Devos
Copyright (C) 2024 Tomas Volf
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License." -->
<title>Cooperative REPL Servers (Guile Reference Manual)</title>
<meta name="description" content="Cooperative REPL Servers (Guile Reference Manual)">
<meta name="keywords" content="Cooperative REPL Servers (Guile Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content=".texi2any-real">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Read_002fLoad_002fEval_002fCompile.html" rel="up" title="Read/Load/Eval/Compile">
<link href="REPL-Servers.html" rel="prev" title="REPL Servers">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Cooperative-REPL-Servers">
<div class="nav-panel">
<p>
Previous: <a href="REPL-Servers.html" accesskey="p" rel="prev">REPL Servers</a>, Up: <a href="Read_002fLoad_002fEval_002fCompile.html" accesskey="u" rel="up">Reading and Evaluating Scheme Code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Cooperative-REPL-Servers-1"><span>6.16.15 Cooperative REPL Servers<a class="copiable-link" href="#Cooperative-REPL-Servers-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-Cooperative-REPL-server"></a>
<p>The procedures in this section are provided by
</p><div class="example lisp">
<pre class="lisp-preformatted">(use-modules (system repl coop-server))
</pre></div>
<p>Whereas ordinary REPL servers run in their own threads (see <a class="pxref" href="REPL-Servers.html">REPL Servers</a>), sometimes it is more convenient to provide REPLs that run at
specified times within an existing thread, for example in programs
utilizing an event loop or in single-threaded programs. This allows for
safe access and mutation of a program&rsquo;s data structures from the REPL,
without concern for thread synchronization.
</p>
<p>Although the REPLs are run in the thread that calls
<code class="code">spawn-coop-repl-server</code> and <code class="code">poll-coop-repl-server</code>,
dedicated threads are spawned so that the calling thread is not blocked.
The spawned threads read input for the REPLs and to listen for new
connections.
</p>
<p>Cooperative REPL servers must be polled periodically to evaluate any
pending expressions by calling <code class="code">poll-coop-repl-server</code> with the
object returned from <code class="code">spawn-coop-repl-server</code>. The thread that
calls <code class="code">poll-coop-repl-server</code> will be blocked for as long as the
expression takes to be evaluated or if the debugger is entered.
</p>
<dl class="first-deffn">
<dt class="deffn" id="index-spawn_002dcoop_002drepl_002dserver"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">spawn-coop-repl-server</strong> <var class="def-var-arguments">[server-socket]</var><a class="copiable-link" href="#index-spawn_002dcoop_002drepl_002dserver"> &para;</a></span></dt>
<dd><p>Create and return a new cooperative REPL server object, and spawn a new
thread to listen for connections on <var class="var">server-socket</var>. Proper
functioning of the REPL server requires that
<code class="code">poll-coop-repl-server</code> be called periodically on the returned
server object.
</p></dd></dl>
<dl class="first-deffn">
<dt class="deffn" id="index-poll_002dcoop_002drepl_002dserver"><span class="category-def">Scheme Procedure: </span><span><strong class="def-name">poll-coop-repl-server</strong> <var class="def-var-arguments">coop-server</var><a class="copiable-link" href="#index-poll_002dcoop_002drepl_002dserver"> &para;</a></span></dt>
<dd><p>Poll the cooperative REPL server <var class="var">coop-server</var> and apply a pending
operation if there is one, such as evaluating an expression typed at the
REPL prompt. This procedure must be called from the same thread that
called <code class="code">spawn-coop-repl-server</code>.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="REPL-Servers.html">REPL Servers</a>, Up: <a href="Read_002fLoad_002fEval_002fCompile.html">Reading and Evaluating Scheme Code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>