Skip to content

Instantly share code, notes, and snippets.

@dszakallas
Created October 29, 2017 12:09
Show Gist options
  • Save dszakallas/b5facb7087ec2769a933680c710f8a16 to your computer and use it in GitHub Desktop.
Save dszakallas/b5facb7087ec2769a933680c710f8a16 to your computer and use it in GitHub Desktop.
clojure.async examples
(ns my-first-clojure-go-routine
(:require [clojure.core.async :refer :all]))
(defn ping [name chan & [start?]]
(go (when start? (>! chan 0))
(loop [i (<! chan)]
(println name i)
(>! chan (inc i))
(if (< i 100) (recur (<! chan)) i))))
(def c (chan))
(ping "Alice" c :start!!!)
(ping "Bob" c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment