From: Christopher Allan Webber Date: Thu, 5 Jan 2017 02:02:13 +0000 (-0600) Subject: Use *init* and *cleanup* in existing actors. X-Git-Tag: v0.4.0~19 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=68472a819457ce0e6053b59b2b9a1657669e8801;p=8sync.git Use *init* and *cleanup* in existing actors. * 8sync/repl.scm (): * 8sync/systems/irc.scm (): Switch from an 'init action to the implicit '*init* action. * 8sync/systems/irc.scm (, irc-bot-cleanup): Add *cleanup* handler. * demos/ircbot.scm: * doc/8sync-new-manual.org: Drop some calls to 'init when bootstrapping-messages since we now use '*init*. --- diff --git a/8sync/repl.scm b/8sync/repl.scm index 0065403..98931ed 100644 --- a/8sync/repl.scm +++ b/8sync/repl.scm @@ -36,7 +36,7 @@ ;; @@: Should we add a stop action? #:init-value (build-actions (*cleanup* repl-manager-cleanup) - (init repl-manager-init)))) + (*init* repl-manager-init)))) (define (repl-manager-cleanup repl-manager message) ;; Close the socket, if open @@ -55,4 +55,3 @@ (while (actor-alive? repl-manager) (poll-coop-repl-server server) (8sleep (repl-manager-poll-every repl-manager)))) - diff --git a/8sync/systems/irc.scm b/8sync/systems/irc.scm index 40d02eb..e6ad361 100755 --- a/8sync/systems/irc.scm +++ b/8sync/systems/irc.scm @@ -164,7 +164,8 @@ (socket #:accessor irc-bot-socket) (actions #:allocation #:each-subclass #:init-value (build-actions - (init irc-bot-init) + (*init* irc-bot-init) + (*cleanup* irc-bot-cleanup) (main-loop irc-bot-main-loop) (send-line irc-bot-send-line-action)))) @@ -191,6 +192,9 @@ (<- (actor-id irc-bot) 'main-loop)) +(define (irc-bot-cleanup irc-bot message) + (close (irc-bot-socket irc-bot))) + (define (irc-bot-main-loop irc-bot message) (define socket (irc-bot-socket irc-bot)) (define line (string-trim-right (read-line socket) #\return)) diff --git a/demos/ircbot.scm b/demos/ircbot.scm index c1c573e..6f32d61 100755 --- a/demos/ircbot.scm +++ b/demos/ircbot.scm @@ -116,14 +116,8 @@ (repl (bootstrap-actor* hive "repl")))) - (define initial-messages - (if repl - (list (bootstrap-message hive irc-bot 'init) - (bootstrap-message hive repl-manager 'init)) - (list (bootstrap-message hive irc-bot 'init)))) - ;; TODO: load REPL - (run-hive hive initial-messages)) + (run-hive hive '())) (define (main args) (define parsed-args (parse-args "ircbot.scm" args)) diff --git a/doc/8sync-new-manual.org b/doc/8sync-new-manual.org index bd6bb31..c4cf67e 100644 --- a/doc/8sync-new-manual.org +++ b/doc/8sync-new-manual.org @@ -165,7 +165,7 @@ yet. Time to fix that! #:username username #:server server #:channels channels)) - (run-hive hive (list (bootstrap-message hive irc-bot 'init)))) + (run-hive hive '())) #+END_SRC Actors are connected to something called a "hive", which is a @@ -434,8 +434,7 @@ Redefine run-bot like so: (bootstrap-actor* hive "repl" #:path repl-path)) - (run-hive hive (list (bootstrap-message hive irc-bot 'init) - (bootstrap-message hive repl-manager 'init)))) + (run-hive hive '())) #+END_SRC If we put a call to run-bot at the bottom of our file we can call it,