core.async

Server push of data from Clojure to ClojureScript

天大地大妈咪最大 提交于 2019-12-03 01:11:46
I'm writing an application server in Clojure that will use ClojureScript on the client. I'd like to find an efficient, idiomatic way to push data from the server to the client as realtime events, ideally using a some combination of: http-kit core.async Ring (But I'm open to other possibilities) Can anyone provide a good example / approach to doing this? I prefer to use aleph , here is the wiki , you can simply use wrap-ring-handler function to wrap existed handlers. For the 'push' function, most useful part is aleph's async handler. It builds on top of netty, not a one connection one thread

Can I make a fully non-blocking backend application with http-kit and core.async?

99封情书 提交于 2019-12-02 15:09:46
I'm wondering if it's possible to put together a fully non-blocking Clojure backend web application with http-kit. (Actually any Ring-compatible http server would be fine by me; I'm mentioning http-kit because it claims to have an event-driven, non-blocking model). EDIT: TL;DR This question is a symptom of some misconceptions I had about the nature of non-blocking/asynchronous/event-driven systems. In case you're in the same place as I was, here are some clarifications. Making an event-driven system with the performance benefits of it being non-blocking (like in Node.js) is possible only if

In Clojure (core.async) what's the difference between alts and alt?

痞子三分冷 提交于 2019-12-01 02:14:24
I can't figure out the difference between: alts! and alt! in Clojure's core.async . alts! is a function that accepts a vector of channels to take from and/or channels with values to be put on them (in the form of doubleton vectors: [c v] ). The vector may be dynamically constructed; the code calling alts! may not know how many channels it'll be choosing among (and indeed that number need not be constant across invocations). alt! is a convenience macro which basically acts as a cross between cond and alts! . Here the number of "ports" (channels or channel+value pairs) must be known statically,

In Clojure (core.async) what's the difference between alts and alt?

◇◆丶佛笑我妖孽 提交于 2019-11-30 21:40:14
问题 I can't figure out the difference between: alts! and alt! in Clojure's core.async. 回答1: alts! is a function that accepts a vector of channels to take from and/or channels with values to be put on them (in the form of doubleton vectors: [c v] ). The vector may be dynamically constructed; the code calling alts! may not know how many channels it'll be choosing among (and indeed that number need not be constant across invocations). alt! is a convenience macro which basically acts as a cross

Clojure - Why does execution hang when doing blocking insert into channel? (core.async)

China☆狼群 提交于 2019-11-30 18:54:34
Consider the following snippet: (let [chs (repeatedly 10 chan)] (doseq [c chs] (>!! c "hello")) (doseq [c chs] (println (<!! c)))) Executing this will hang forever. Why is that? If I do (go (>! c "hello")) instead, it works just fine. To make an asynchronous put, use clojure.core.async/put! (let [chs (repeatedly 10 chan)] (doseq [c chs] (put! c "hello")) (doseq [c chs] (println (<!! c)))) This works in this example as <!! will always unblock because of all necessary puts happening asynchronously. Notice the following things: Blocking serves as a synchronization constraint between different

Clojure core.async, any way to control number of threads in that (go…) thread pool?

流过昼夜 提交于 2019-11-30 05:23:41
By default (go..) will use twice the number of cores + 42 threads for the thread pool. Is there any way I can set the number of threads, or number of CPUs that the code can use, through setting an environment variable or sth? On linux machine I can set number of CPU using taskset , e.g. taskset -c 0,1 my_Java_or_Clojure_program , although taskset seems not effective on the number returned by (-> (java.lang.Runtime/getRuntime) .availableProcessors) . In the current Clojure version of core.async, the thread pool executor is located in the clojure.core.async.impl.dispatch namespace. You can alter

couldn't use for loop in go block of core.async?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 13:28:19
I'm new to clojure core.async library, and I'm trying to understand it through experiment. But when I tried: (let [i (async/chan)] (async/go (doall (for [r [1 2 3]] (async/>! i r))))) it gives me a very strange exception: CompilerException java.lang.IllegalArgumentException: No method in multimethod '-item-to-ssa' for dispatch value: :fn and I tried another code: (let [i (async/chan)] (async/go (doseq [r [1 2 3]] (async/>! i r)))) it have no compiler exception at all. I'm totally confused. What happend? So the Clojure go-block stops translation at function boundaries, for many reasons, but the

Clojure core.async, any way to control number of threads in that (go…) thread pool?

佐手、 提交于 2019-11-29 03:48:45
问题 By default (go..) will use twice the number of cores + 42 threads for the thread pool. Is there any way I can set the number of threads, or number of CPUs that the code can use, through setting an environment variable or sth? On linux machine I can set number of CPU using taskset, e.g. taskset -c 0,1 my_Java_or_Clojure_program , although taskset seems not effective on the number returned by (-> (java.lang.Runtime/getRuntime) .availableProcessors) . 回答1: In the current Clojure version of core

couldn't use for loop in go block of core.async?

我与影子孤独终老i 提交于 2019-11-28 07:19:40
问题 I'm new to clojure core.async library, and I'm trying to understand it through experiment. But when I tried: (let [i (async/chan)] (async/go (doall (for [r [1 2 3]] (async/>! i r))))) it gives me a very strange exception: CompilerException java.lang.IllegalArgumentException: No method in multimethod '-item-to-ssa' for dispatch value: :fn and I tried another code: (let [i (async/chan)] (async/go (doseq [r [1 2 3]] (async/>! i r)))) it have no compiler exception at all. I'm totally confused.