Questions tagged [core.async]

A clojure/clojurescript library for asynchronous programming.

core.async is a clojure/clojurescript library to allow a model of asynchronous programming similar to that of the Go language.

229 questions
0
votes
1 answer

Sleeping barber in Clojure

I'm implementing Sleeping barber using core.async. My current code is: (def workingtime 10000) (defn barber [in waiting-room] (go-loop [served-customers 0] (let [[v] (alts! [waiting-room in])] (if (= v :close) …
Konstantin Milyutin
  • 10,842
  • 11
  • 53
  • 77
0
votes
1 answer

How to make manifold stream with dropping buffer?

Using core.async I'm able to easily create a channel with dropping buffer: (async/chan (async/dropping-buffer 10)) Is it possible to create manifold stream with dropping buffer?
OlegTheCat
  • 4,173
  • 14
  • 22
0
votes
2 answers

How to prevent close!-ing before put-ing in onto-chan

I'd like to run a code like (->> input (partition-all 5) (map a-side-effect) dorun) asynchronously dividing input and output(a-side-effect). Then I've written the code to experiment below. ;; using boot-clj (set-env! :dependencies…
ryo
  • 119
  • 1
  • 2
  • 4
0
votes
1 answer

Structuring clojure code with go blocks

I am using jet for asynchronous ring adapter. Jet also comes with async http-client which returns a channel whose value's :body is also a channel. Also, async server route handler can return a map whose :body key can contain a channel. When this…
Ashish Negi
  • 4,733
  • 6
  • 44
  • 85
0
votes
1 answer

Putting then immediately removing value from channel causes weird behavior (ClojureScript core.async)

The following is a contrived example for learning purposes. It involves jamming the value "val" into a channel and then immediately removing it within a go block: (def test-chan1 (chan)) (go (println (
George
  • 5,909
  • 2
  • 24
  • 53
0
votes
2 answers

Placing a value at the bottom of a channel?

In Clojure(Script), is there anyway to jam a value at the bottom (as opposed to the top) of a channel so that the next time it is taken from (for example by using
George
  • 5,909
  • 2
  • 24
  • 53
0
votes
2 answers

Clojurescript ajax.core without separate handler/callback, with very precise flow in the code as if the code was sync

In javascript I could write some code like: var app_state={"context":"loading"}; $.get("") .then(function(data){ app_state["data"]=data; }) .then(change("context", "edit")) .then(render) In Clojurescript, I'd like something like: (->…
Dan Bunea
  • 167
  • 2
  • 10
0
votes
1 answer

Idiomatic clojure: taking multiple items off a channel

I have a channel into which I am putting a number of individual values (JSON lines, incidentally). In taking values off the channel, I wish to batch-process them as a group. Is there any notion of take n from the channel or else a means to bundle…
David
  • 964
  • 6
  • 14
0
votes
1 answer

Clojure - core.async interface for apache kafka

I am using clj-kafka, and I am trying to make a core.async interface to it in the REPL. I am getting some messages, but my structure feels wrong : I either cannot stop receiving messages, or have to launch the go routine again to receive more…
nha
  • 16,039
  • 11
  • 76
  • 108
0
votes
2 answers

When will channel be discarded when a thread keeps taking from it?

Consider the following piece of code taken from the example walkthrough of core.async: (let [c1 (chan) c2 (chan)] (thread (while true (let [[v ch] (alts!! [c1 c2])] (println "Read" v "from" ch)))) (>!! c1…
schaueho
  • 3,269
  • 1
  • 19
  • 30
0
votes
2 answers

Multiple listeners / go blocks for channel in ClojureScript

Given a channel in ClojureScript (def navigation (chan)) Is it possible to have multiple go blocks that pull values off it? E.g. (go (while true (secretary/dispatch! (
Samuel
  • 2,169
  • 1
  • 21
  • 35
0
votes
1 answer

core.async machine that loops until a fx returns true

While loading a web site, I often have the need to load code AFTER some other DOM structural event has occurred. Therefore I often end up with a lot of functions that first check if some element exist in the DOM and then do their thing in the event…
Stephen Cagle
  • 12,627
  • 14
  • 49
  • 83
0
votes
1 answer

Performance counter for Clojure (using core.async)

I am wondering what is the best way to implement performance counters in Clojure for a particular task that runs concurrently. I usually end up having something like this: (defn -main [& args] (let [c (async/chan)] (doseq [_ (range 50)] …
Istvan
  • 6,372
  • 7
  • 43
  • 81
0
votes
1 answer

What is the idiomatic way to stop the event propagation with core.async (ClojureScript)?

I have a very simple use case: in a text area, I want to stop the event propagation for some key codes and trigger some function f, and for other key codes, I just trigger some function g. So I've defined a channel called out and a listener, which…
0
votes
1 answer

Trying to create an asynchronous example using Core.Async.Pipe, but Pipe.write seems to block awaiting a Pipe.read

I've created the following toy example that counts in a loop and writes the value to an Async.Pipe: open Sys open Unix open Async.Std let (r,w) = Pipe.create () let rec readloop r = Pipe.read r >>= function | `Eof -> return () | `Ok v ->…
aneccodeal
  • 7,651
  • 6
  • 38
  • 70
1 2 3
15
16