Skip to content

Instantly share code, notes, and snippets.

@w01fe
Last active December 20, 2015 01:19
Show Gist options
  • Save w01fe/6047895 to your computer and use it in GitHub Desktop.
Save w01fe/6047895 to your computer and use it in GitHub Desktop.
chan->lazy-seq
(ns async.core
(:require [clojure.core.async :as a]))
(def c (a/chan 10))
(a/go
(loop [i 0]
(println "putting" i)
(a/>! c i)
(if (< i 100)
(recur (inc i))
(a/close! c))))
(defn chan->seq [chan]
(let [p (promise)]
(a/take! chan #(deliver p %))
(when @p
(cons @p (lazy-seq (chan->seq chan))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment