agenda: When re-invoking a continuation at the agenda, don't wrap in a catch.
[8sync.git] / 8sync / repl.scm
1 ;;; 8sync --- Asynchronous programming for Guile
2 ;;; Copyright (C) 2015 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;;
4 ;;; This file is part of 8sync.
5 ;;;
6 ;;; 8sync is free software: you can redistribute it and/or modify it
7 ;;; under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation, either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; 8sync is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU Lesser General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with 8sync.  If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (8sync repl)
20   #:use-module (oop goops)
21   #:use-module (8sync)
22   #:use-module (system repl server)
23   #:use-module (system repl coop-server)
24   #:export (<repl-manager>))
25
26 (define-class <repl-manager> (<actor>)
27   (path #:init-keyword #:path
28         #:init-value "/tmp/8sync-socket"
29         #:getter repl-manager-path)
30   (socket #:init-value #f
31           #:accessor repl-manager-socket)
32   (poll-every #:init-keyword #:poll-every
33               #:init-value (/ 1 30)
34               #:getter repl-manager-poll-every)
35   (actions #:allocation #:each-subclass
36            ;; @@: Should we add a stop action?
37            #:init-value (build-actions
38                          (*cleanup* repl-manager-cleanup)
39                          (init repl-manager-init))))
40
41 (define (repl-manager-cleanup repl-manager message)
42   ;; Close the socket, if open
43   (and=> (repl-manager-socket repl-manager)
44          close)
45   ;; Delete the file, if it exists
46   (when (file-exists? (repl-manager-path repl-manager))
47     (delete-file (repl-manager-path repl-manager))))
48
49 (define (repl-manager-init repl-manager message)
50   (define socket
51     (make-unix-domain-server-socket #:path (repl-manager-path repl-manager)))
52   (define server
53     (spawn-coop-repl-server socket))
54   (set! (repl-manager-socket repl-manager) socket)
55   (while (actor-am-i-alive? repl-manager)
56     (poll-coop-repl-server server)
57     (8sleep (repl-manager-poll-every repl-manager))))
58