From: Christopher Allan Webber Date: Sat, 12 Aug 2017 15:21:53 +0000 (-0500) Subject: repl: Add spawn-repl, a simpler cooperative repl interface using spawn-fiber. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=a02a901d3869fc56d10597347ccbdd0df5c7e119;p=8sync.git repl: Add spawn-repl, a simpler cooperative repl interface using spawn-fiber. Keeping around the old actor for now because it's displaying memory leak problems, and I want to figure out what those are. * 8sync/repl.scm (spawn-repl): New variable. --- diff --git a/8sync/repl.scm b/8sync/repl.scm index 4cf60b2..ddcd50b 100644 --- a/8sync/repl.scm +++ b/8sync/repl.scm @@ -19,11 +19,14 @@ (define-module (8sync repl) #:use-module (oop goops) #:use-module (8sync) + #:use-module (fibers) #:use-module (8sync daydream) #:use-module (srfi srfi-1) + #:use-module (ice-9 atomic) #:use-module (system repl server) #:use-module (system repl coop-server) - #:export ()) + #:export ( + spawn-repl)) (define-actor () ((add-subscriber repl-manager-add-subscriber) @@ -79,3 +82,24 @@ (set! (.subscribers repl-manager) (remove (lambda (x) (equal? x (message-from message))) (.subscribers repl-manager)))) + + + +(define* (spawn-repl #:key (path "/tmp/8sync-socket") + (socket (make-unix-domain-server-socket #:path path)) + (poll-every 1/30) + (stop? (make-atomic-box #f)) + (on-update #f)) + "Spawn a cooperative REPL in a new fiber." + (define server + (spawn-coop-repl-server socket)) + (spawn-fiber + (lambda () + (while (not (atomic-box-ref stop?)) + ;; Poll the server + (poll-coop-repl-server server) + ;; Call update hook, if any + (and on-update (on-update)) + ;; Take a break! + (sleep poll-every)) + (close socket))))