Last active
January 9, 2019 21:03
-
-
Save souenzzo/2d3e171bf718e32becf3cb9d15ea6dfa to your computer and use it in GitHub Desktop.
core.async cljs bug. Run 'clj -m cljs.main --repl-env node -m hack'
This file contains 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
;; clj -Srepro -Sdeps '{:deps {cljs-bug {:git/url "https://gist.github.com/souenzzo/2d3e171bf718e32becf3cb9d15ea6dfa" :sha "eded47447764e7eb8d4cb25be1d77640e9c50aaf"}}}' -m hack ## works! | |
;; clj -Srepro -Sdeps '{:deps {cljs-bug {:git/url "https://gist.github.com/souenzzo/2d3e171bf718e32becf3cb9d15ea6dfa" :sha "eded47447764e7eb8d4cb25be1d77640e9c50aaf"}}}' -m cljs.main --repl-env node -m hack ## Can't recur here at line 44 hack.cljc | |
{:paths ["."] | |
:deps {org.clojure/clojure {:mvn/version "1.10.0"} | |
org.clojure/clojurescript {:mvn/version "1.10.439"} | |
org.clojure/core.async {:mvn/version "0.4.490"}}} | |
This file contains 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 hack | |
(:require [clojure.core.async :as async] | |
[clojure.core.async.impl.protocols :as async.protocols]) | |
(:import #?(:clj (clojure.lang Counted)))) | |
(defn constantly-buffer | |
[v] | |
(let [vs (atom [v])] | |
(reify | |
async.protocols/UnblockingBuffer | |
async.protocols/Buffer | |
(full? [this] false) | |
(remove! [this] (first @vs)) | |
(add!* [this v] | |
(reset! vs [v]) | |
this) | |
(close-buf! [this] | |
(reset! vs []) | |
nil) | |
#?@(:cljs [ICounted | |
(-count [this] (count @vs))] | |
:clj [Counted | |
(count [this] (count @vs))])))) | |
(defn- async-loop-fn | |
[bindings body] | |
`(let [c# (async/chan (constantly-buffer true))] | |
(async/go-loop ~bindings | |
(when-let [continue?# (async/<! c#)] | |
~@body)) | |
c#)) | |
(defmacro async-loop | |
[bindings & body] | |
(async-loop-fn bindings body)) | |
(def gps (async/chan)) | |
(defn -main [& args] | |
(try (async-loop [] | |
(let [position (async/<! gps)] | |
(prn position) | |
(recur))) | |
(catch Exception e | |
(println e))) | |
(prn :exit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment