(ns advent.action-test2 (:require [clojure.core.async :refer [put! ! chan go thread take! alts!!]])) (defprotocol IAction (begin [this state]) (done? [this state]) (continue [this state]) (terminate [this state])) (defn talk [action-channel who text] (let [c (chan)] (put! action-channel (reify IAction (begin [this state] (println "Speaking:" text) (assoc state :time 0)) (continue [this state] (Thread/sleep 200) (assoc state :time (inc (:time state)))) (done? [this {:keys [time]}] (< 3 time)) (terminate [this state] (put! c state) state))) (= x target-x) (>= y target-y))) (terminate [this state] (put! c state) state)))) (