Karsten Schmidt  committed b7b5754

adding disconn! function and making it (and conn! too) blocking, adding new unit test

  • Participants
  • Parent commits 01977aa

Comments (0)

Files changed (2)

File src/estuary/core.clj

   "Creates a connection from the given source node to a target node. The nodes need to be either supplied
 as variables or UUIDs. The port parameter is the key of the target's input terminal."
   ([src target port]
-    (send-off src
+    (send src
       (fn [state]
-        (assoc state :targets (conj (:targets state) {:agent target :id (:id @target) :port port})))))
+        (assoc state :targets (conj (:targets state) {:agent target :id (:id @target) :port port})))) (await src))
   ([g sid tid port]
     (let [src (get-node g sid) t (get-node g tid)]
-      (send-off src
+      (send src
         (fn [state]
-          (assoc state :targets (conj (:targets state) {:agent t :id tid :port port})))))))
+          (assoc state :targets (conj (:targets state) {:agent t :id tid :port port})))) (await src))))
+(defn disconn!
+  "Removes the connection between two nodes, either as defined by their node UUIDs and port name or via variables."
+  ([src target port]
+    (let [tid (:id @target) targets (filter #(not (and (= (:id %) tid) (= (:port %) port))) (:targets @src))]
+      (send-off src assoc :targets targets) (await src)))
+  ([g sid tid port]
+    (let [src (get-node g sid)
+          targets (filter #(not (and (= (:id %) tid) (= (:port %) port))) (:targets @src))]
+      (send src assoc :targets targets) (await src))))
 (defmacro defgraph
   "Creates a new atom based map container for nodes and assigns it to the given variable."

File test/estuary/test/core.clj

   (send-off a set-value 1000)
   (Thread/sleep 100)
   (is (= 1000 (:value @b)))
-  (is (= 2000 (:value @c))))
+  (is (= 2000 (:value @c))))
+(deftest remove-conn
+  (defgraph g)
+  (defnode g a `set-value {:value 0})
+  (defaccu g b `set-and-accumulate 2)
+  (conn! a b :in0)
+  (conn! a b :in1)
+  (is (= 2 (count (:targets @a))))
+  (disconn! a b :in0)
+  (disconn! a b :in1)
+  (is (= 0 (count (:targets @a)))))