Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Previous: , Up: Read/Load/Eval/Compile   [Contents][Index]

6.17.13 Cooperative REPL Servers

The procedures in this section are provided by

(use-modules (system repl coop-server))

Whereas ordinary REPL servers run in their own threads (see REPL Servers), 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’s data structures from the REPL, without concern for thread synchronization.

Although the REPLs are run in the thread that calls spawn-coop-repl-server and poll-coop-repl-server, 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.

Cooperative REPL servers must be polled periodically to evaluate any pending expressions by calling poll-coop-repl-server with the object returned from spawn-coop-repl-server. The thread that calls poll-coop-repl-server will be blocked for as long as the expression takes to be evaluated or if the debugger is entered.

Scheme Procedure: spawn-coop-repl-server [server-socket]

Create and return a new cooperative REPL server object, and spawn a new thread to listen for connections on server-socket. Proper functioning of the REPL server requires that poll-coop-repl-server be called periodically on the returned server object.

Scheme Procedure: poll-coop-repl-server coop-server

Poll the cooperative REPL server coop-server 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 spawn-coop-repl-server.