clojureluminus

Create multi thread in clojure


I have this code:


      (do 
               ;**[1]** 
        (.start (Thread. 
          (http/get "http://127.0.0.1:8001/cardiologista/api/auth/ms1"
                       {:query-params {:verify "my-hash"}}))
        )
            ;**[2]**
        (.start (Thread. 
               (let [session (:session request)]
                   (-> (redirect "/client/dashboard")
                       (assoc :session verifica))))
        )
      )

I want to make a get call ([1]) and I don't want to wait for the callback (I won't use the callback), however, I don't want to wait for the response from that call to redirect ([2]) the page, I tried to do it that way (using thread), but it didn't work right.

In short: I want to make a GET call [1] and after that call to call the redirect function [2], but I cannot wait for the GET call to respond. (I don't know if this would solve using thread)


Solution

  • As the friend said in the comments, I used future to solve the problem, the function was like this:

    (do 
      (future 
        (http/get "http://127.0.0.1:8001/cardiologista/api/auth/ms1"
                  {:query-params {:verify "my-hash"}}))
      (let [session (:session request)]
        (-> (redirect "/cliente/dashboard")
            (assoc :session verifica))))