    [taoensso.timbre :refer [info warn error]]))
 
 (defprotocol IVertex
-  (connect-to! [_ v sig-fn])
+  (connect-to! [_ v sig-fn edge-opts])
   (disconnect-from! [_ v])
   (disconnect! [_])
   (input-channel [_])
+  (collect! [_])
+  (score-collect [_])
   (signal! [_])
+  (score-signal [_])
   (receive-signal [_ src sig]))
 
 (defprotocol IComputeGraph
   (add-vertex! [_ vstate])
+  (vertex-for-id [_ id])
   (vertices [_]))
 
 (defprotocol IGraphExecutor


(defn default-collect
  [vertex]
  (swap! (:state vertex) #(update % :val into (:uncollected %))))

(defn signal-forward [state] (:val state))

(defn default-score-signal
  [{:keys [state last-sig-state] :as vertex}]
  (if (= (:val @state) @last-sig-state) 0 1))

(defn default-score-collect
  [vertex] (-> vertex :state deref :uncollected count))

(defn should-signal?
  [vertex thresh]
  (> ((-> vertex :state deref :score-signal) vertex) thresh))

(defn should-collect?
  [vertex thresh]
  (> ((-> vertex :state deref :score-collect) vertex) thresh))

(defrecord Vertex [id state last-sig-state in outs]
  IVertex
  (connect-to!
    [_ v sig-fn]
    (swap! outs assoc v sig-fn) _)
  (disconnect-from!
    [_ v] (swap! outs dissoc v) _)
  (disconnect! [_]
    (close! in) _)
  (input-channel
    [_] in)
  (signal!
    [_]
    (let [state @state]
      (reset! last-sig-state (:val state))
      (go-loop [outs @outs]
        (let [[v f] (first outs)]
          (when v
            (>! (input-channel v) [id (f state)])
            (recur (next outs)))))
      _))
  (receive-signal

                 (update :vertices assoc id v)
                 (assoc  :curr-vertex v)))))
        :curr-vertex))
  (vertex-for-id
    [_ id] (-> @state :vertices id))
  (vertices
    [_] (-> @state :vertices vals)))

