             sub-ch (chan)
             fetch-ch (chan)]
         (async/sub p :new-meta sub-ch false)
-        (subscribe sub-ch bus-out (print-chan "SUBSOUT" out))
+        (subscribe sub-ch bus-out out #_(print-chan "SUBSOUT" out))
 
         (async/sub p :meta-up pub-ch false)
         (async/sub p :fetched fetch-ch false)

                                             2 42
                                             3 43}})
           (recur (<! in))))


(defn realize-value [stage store eval-fn]



(defn sync! [peer stage]
  (go (let [{:keys [type author chans new-values meta] :as new-stage} (<! (ensure-conn peer stage))
            [in out] chans
            p (async/pub in :type)
            fch (chan)]

        (async/sub p :fetch fch)
        (case type
          :meta-up (>! out {:type :meta-up :user author :meta meta})
          :new-meta (do
                      (>! out {:type :new-meta :user author :repo (:id meta)})
                      (>! out {:type :meta-up :user author :meta meta})))

        (let [to-fetch (select-keys new-values (:ids (<! fch)))]
          (>! out {:type :fetched
                   :fetched to-fetch}))

        (dissoc new-stage :type :new-values))))


#_(def mem-store (new-store))
#_(def peer (fake-peer mem-store))

#_(go (let [peer (fake-peer mem-store)
          new-stage (<! (sync! peer (repo/new-repository "me@mail.com"
                                                         {:type "s" :version 1}
                                                         "Testing."
                                                         false
                                                         {:some 42})))
          in (first (:chans new-stage))]

      (println "publication:" (<! in))))



#_(let [in (chan)
      out (chan)
      p (async/onto-chan out [{:type :new-meta
                               :user "john" :repo 1}
                              #_{:type :publish :user "maria" :repo 3 :meta {:win :ning}}
                              #_{:type :subscribe
                                 :user "maria" :repo 3}
                              {:type :meta-up
                               :user "john" :meta {:id 1
                                                   :causal-order {1 #{}
                                                                  2 #{1}}
                                                   :last-update (java.util.Date. 0)
                                                   :schema {:type ::geschichte
                                                            :version 1}}}]
                         false)]
    (go (wire peer [in out])
        (<! p))

  (go-loop [i (<! in)]
           (println "received:" i)
