 
 (ns cbfg.core
   (:require-macros [cljs.core.async.macros :refer [go go-loop]]
-                   [cbfg.ago :refer [ago ago-loop achan-buf aput atake]])
+                   [cbfg.ago :refer [ago ago-loop achan-buf aclose aput atake]])
   (:require [clojure.string :as string]
             [cljs.core.async :refer [<! >! put! chan timeout merge]]
             [goog.dom :as gdom]


;; ------------------------------------------------

(defn example-add [actx x y delay]
  (ago example-add actx
       (<! (timeout delay))
       (+ x y)))

(defn example-sub [actx x y delay]
  (ago example-sub actx
       (<! (timeout delay))
       (- x y)))

(def cmd-handlers {"add" (fn []
                           (let [x (js/parseInt (get-el-value "x"))
                                 y (js/parseInt (get-el-value "y"))
                                 fence (get-el-value "fence")
                                 delay (js/parseInt (get-el-value "delay"))]
                             {:rq #(example-add % x y delay) :fence (= fence "1")})),
                   "sub" (fn []
                           (let [x (js/parseInt (get-el-value "x"))
                                 y (js/parseInt (get-el-value "y"))
                                 fence (get-el-value "fence")
                                 delay (js/parseInt (get-el-value "delay"))]
                             {:rq #(example-sub % x y delay) :fence (= fence "1")}))})

(defn vis-init []
  (let [cmds (merge [(listen (gdom/getElement "add") "click")

                               (recur (conj acc result))))]
           (ago-loop main-in w-actx []
                     (let [cmd (.-id (.-target (<! cmds)))
                           cmd-doer ((get cmd-handlers cmd) (achan-buf main-in 1))]
                       (aput main-in in cmd-doer)
                       (recur)))))))

(vis-init)
