Updating copyright headers to be more "modern"
[8sync.git] / eightsync / 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 (eightsync repl)
20   #:use-module (ice-9 q)
21   #:use-module (eightsync agenda)
22   #:use-module (system repl coop-server)
23   #:export (make-coop-server-handler
24             spawn-and-queue-repl-server!))
25
26 (define (make-coop-server-handler coop-server)
27   (define (run-self)
28     (poll-coop-repl-server coop-server)
29     ;; queue ourselves again
30     (run-delay (run-self) (/ 1 30)))
31   run-self)
32
33 (define* (spawn-and-queue-repl-server! agenda #:optional port)
34   (let ((coop-server
35          (if port
36              (spawn-coop-repl-server port)
37              (spawn-coop-repl-server))))
38     (enq! (agenda-queue agenda)
39           (make-coop-server-handler coop-server))))