-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clojure REPL in async environments does not eval output #572
Comments
Since is not a private code I will submit it here to fast testing with the actual environment, it's a tutorial code. (ns hospital.aula6
(:use [clojure pprint])
(:require
[hospital.model :as h.model]))
(defn cabe-na-fila?
[fila]
(-> fila
count
(< 5)))
(defn chega-em
[fila pessoa]
(if (cabe-na-fila? fila)
(conj fila pessoa)
(throw (ex-info "Fila já está cheia" {:tentando-adiconar pessoa}))))
(defn chega-em! [hospital pessoa]
(let [fila (get hospital :espera)]
(alter fila chega-em pessoa)))
(defn simula-um-dia
[]
(let [hospital {:espera (ref h.model/empty-queue)
:laboratorio1 (ref h.model/empty-queue)
:laboratorio2 (ref h.model/empty-queue)
:laboratorio3 (ref h.model/empty-queue)}]
(dosync
(chega-em! hospital "guilherme")
(chega-em! hospital "ana")
(chega-em! hospital "paulo")
(chega-em! hospital "paloma")
(chega-em! hospital "maria")
(chega-em! hospital "david"))
(pprint hospital)))
(simula-um-dia)
(defn async-chega-em! [hospital pessoa]
(future
(Thread/sleep (rand 5000))
(dosync
(pprint "Tentando adicionar pessoa" pessoa)
(chega-em! hospital pessoa))))
(defn simula-um-dia-async
[]
(let [hospital {:espera (ref h.model/empty-queue)
:laboratorio1 (ref h.model/empty-queue)
:laboratorio2 (ref h.model/empty-queue)
:laboratorio3 (ref h.model/empty-queue)}]
(async-chega-em! hospital 15)
(pprint hospital)))
(simula-um-dia-async)
|
So you are expecting to see "Tentando adicionar pessoa" in the log and you are not? Do you see the output in you Clojure nREPL window instead? Because you're Running If you are expecting to see values in That part is just how Clojure (and all async programming) works and isn't something I can change I'm afraid. So! If your question is about the I hope this helps! |
When trying to print things or get values from an async implementation usually the thing you wanna spill out will not show unless is the last action of a function.
The text was updated successfully, but these errors were encountered: