Add repl.scm (can't believe I forgot it before!) and use it in irc.scm
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 01:36:43 +0000 (19:36 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 01:36:43 +0000 (19:36 -0600)
demos/irc.scm
eightsync/repl.scm [new file with mode: 0644]

index 7a8d2ab020e478b740699b893e12fb24cd525c00..2ff8c8cfda8360003f7dc90cc2ec6e521f8b3053 100755 (executable)
                    default-irc-port))
          (username (option-ref options 'username #f))
          (listen (option-ref options 'listen #f))
-         (channels (option-ref options 'channels "")))
+         (channels (option-ref options 'channels ""))
+         (agenda (make-agenda)))
     (display `((server ,hostname) (port ,port) (username ,username)
                (listen ,listen) (channels-split ,(string-split channels #\space))))
     (newline)
+    (if listen
+        (spawn-and-queue-repl-server! agenda))
     (queue-and-start-irc-agenda!
-     (make-agenda)
+     agenda
      (irc-socket-setup hostname port)
      #:inet-port port
      #:username username
diff --git a/eightsync/repl.scm b/eightsync/repl.scm
new file mode 100644 (file)
index 0000000..6180d04
--- /dev/null
@@ -0,0 +1,38 @@
+;; Copyright (C) 2015 Christopher Allan Webber <cwebber@dustycloud.org>
+
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 3 of the License, or (at your option) any later version.
+;;
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; Lesser General Public License for more details.
+;;
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+;; 02110-1301 USA
+
+(define-module (eightsync repl)
+  #:use-module (ice-9 q)
+  #:use-module (eightsync agenda)
+  #:use-module (system repl coop-server)
+  #:export (make-coop-server-handler
+            spawn-and-queue-repl-server!))
+
+(define (make-coop-server-handler coop-server)
+  (define (run-self)
+    (poll-coop-repl-server coop-server)
+    ;; queue ourselves again
+    (run-delay (run-self) (/ 1 60)))
+  run-self)
+
+(define* (spawn-and-queue-repl-server! agenda #:optional port)
+  (let ((coop-server
+         (if port
+             (spawn-coop-repl-server port)
+             (spawn-coop-repl-server))))
+    (enq! (agenda-queue agenda)
+          (make-coop-server-handler coop-server))))