Created
June 9, 2014 15:56
-
-
Save pingles/d12314ecdff0a319091b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns async.example | |
(:require [clojure.core.async :refer (chan go-loop <! >!)]) | |
(:import [java.util Date]) | |
(:gen-class)) | |
(defn producer-process [channel] | |
(go-loop [] | |
(>! channel (str "Hello, the time is " (Date.))) | |
(Thread/sleep 500) | |
(recur))) | |
(defn consumer-process [channel] | |
(go-loop [message (<! channel)] | |
(println "Received:" message) | |
(recur (<! channel)))) | |
(defn wait! [] | |
(let [s (java.util.concurrent.Semaphore. 0)] | |
(.acquire s))) | |
(defn -main [& args] | |
(let [c (chan)] | |
(producer-process c) | |
(consumer-process c) | |
(wait!))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment