Synchronous concurrency: Difference between revisions

changed lang tag for Clojure
(changed lang tag for Clojure)
Line 160:
The ''state'' argument is the agent's state at the start of the call, and the last expression becomes the agent's new state.
 
<lang lispclojure>(import '(java.io FileReader BufferedReader) ;used in the reader
 
(def writer (agent 0))
Line 170:
The reader executes on the main thread. It passes each line to the writer -- the ''send'' call returns immediately, waits until the writer has finished writing all the lines, gets the line count & prints it, and terminates the writer.
 
<lang lispclojure>(doseq [line (-> "input.txt" FileReader. BufferedReader. line-seq)]
(send writer write-line line))
(await writer)
Anonymous user