Clojure idiomatic for thread synchronization

The scenario I'm trying to solve is this: I have a testing program that makes the network the network endpoint on the system.

In this test program, the berth server runs on which it expects a callback from an external system, which completes the successful testing cycle. If the callback is not received within a certain time interval (timeout), the test is not performed.

To achieve this, I want the tester to wait for the “event” that the berth handler will set after the callback.

I was thinking about using java CyclicBarrier, but I am wondering if clojure has an idiomatic way to solve this problem.

thank

+5
source share
2 answers

promise, :) - :

(def completion (promise))

; In test runner.
; Wait 5 seconds then fail.
(let [result (deref completion 5000 :fail)]
   (if (= result :success) 
     (println "Great!") 
     (println "Failed :(")))

; In jetty on callback
(deliver completion :success)
+6

Clojure , , , Aleph, -, . , , .

+3

All Articles