Commits

Karsten Schmidt committed b7b5754

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

Comments (0)

Files changed (2)

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."

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)))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.