Timothy Baldridge - Core.Async

ClojureTV · 30K views · 2013 · 39:46

Open on YouTube

Functional programmingSoftware architecture & designProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it as the standard introduction to core.async, citing it to explain channel semantics, the ! and !! naming, and ClojureScript REPL and callback-wrapping patterns.

Recommended by 3 people across 3 different months, 2014 to 2016.

What it is

A 2013 Clojure/conj talk by Timothy Baldridge introducing the core.async library. It begins with an overview of channels and go blocks, then shows examples ported from other CSP languages such as Go and JSCP, and ends with a program that runs on both Clojure and ClojureScript.

What people said

Recommends tangrammer · 2014-02 · Stack Overflow · on “What is the advantage of core.async in clojurescript?”

Great question! I think your first step to understand the advantage would be Timothy Baldridge Video [this video] And below my try: I think that the differences will clear up if we change a bit your code. Firstly, trying to highlight the sentence "There comes a time in all good programs when components or subsystems must stop communicating directly with one another" extracted from the presentation of core.async posted on the clojure blog [LINK] . I think that we can separate the input events channel from the let fn: (def clicks (listen (dom/getElement "search1") "click")) (go (while true (dosomethingasync (<! clicks)))) (put! clicks "this channel can be written from differents parts of your code"

Recommends Chris Murphy · 2015-09 · Stack Overflow · on “Clojure: log to console when code is being executed in a go block or thread”

This answer uses core.async itself. The following from a talk: ;;;;; Logging Handler ;;;;; (def log-chan (chan)) (thread (loop [] (when-let [v (<!! log-chan)] (println v) (recur))) (println "Log Closed")) (close! log-chan) (defn log [msg] (>!! log-chan msg)) (log "foo") Code copied verbatim from here [LINK] Talk was by Timothy Balridge and is here [this video] I have an atom for turning debugging on and off. To be precise about the messages that are displayed the usage is like this: (u/log @debug (str "Asked " info-ele ", and got back: " some-return)) At the other end like this: (defn log [debug msg] (when debug (>!! log-chan msg)))

Recommends beatngu13 · 2016-08 · Stack Overflow · on “Where do the function names in clojure.core.async derive from and could they use descriptive ones?”

A tiny mnemonic: think of > respectively < as a funnel that acts like an endpoint of your chan nel. ! (or !! ) is the message you'd like to put into ( >! ) or take from ( <! ) that channel. [LINK] Unfortunately, I can give you no explanation why ! stands for parking and !! for blocking, but I think you get used to it real quick. Furthermore, it lets you write concise code that doesn't distract from the actual business logic. EDIT: After watching Timothy Baldridge's talk on core.async from Clojure/conj 2013 [this video] , I'd like to add this quote (skip to 6:15 [this video] ): […] the first exclamation mark kind of means that it's not transaction-safe […] and the second one just signifies that this is

Cites hawkeye · 2014-01 · Stack Overflow · on “How to show generated JS in Clojurescript REPL?”

In this presentation [this video] on core.async Timothy Baldridge c onnects to a ClojureScript Browser [LINK] REPL and sends generated JavaScript to a web browser from Emacs. When I work through the Austin (Clojurescript REPL) steps [LINK] here I don't get generated JavaScript as I see in the video. What am I missing? My question is: How to show generated JS in Clojurescript REPL?

Cites tangrammer · 2014-05 · Stack Overflow · on “Why am I only getting one take! from this channel?”

The println behavior is quiet weird in this async scenario. If your last invocation is the "take!" fn then you'll end up with the print result in your repl, but is four last invocation is the "put!" fn then you have to find the print result on the nrepl-server terminal. This behavior and necessary workspace it's introduced on the beginning of Timothy Baldridge video [this video] of core.async And here one screenshot [LINK] of my 2 frames in emacs, one for the nrepl and the other for the nrepl-server output

Cites Valentin Waeselynck · 2014-07 · Stack Overflow · on “Can I make a fully non-blocking backend application with http-kit and core.async?”

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 [LINK] 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 all (say, most) of your IO is handled in a non-blocking way from the ground up . This means tha

Cites Steve Kuo · 2015-05 · Stack Overflow · on “Clojure core.async, channel vs port”

In Clojure core.async, are channels and ports the same thing? If not what's the difference? In watching the video Timothy Baldridge - Core.Async [this video] , he creates a channel (def c (chan)) Then later (<!! c) c is channel yet the docs for <!! state (emphasis added) Usage: (<!! port) takes a val from port . Will return nil if closed. Will block if nothing is available. It's not clear looking at the core.async docs [LINK] .

Cites nha · 2015-08 · Stack Overflow · on “Clojurescript - Uncaught Error: <! used not in (go ...) block”

I am in Clojurescript, and trying to use core.async [LINK] to get a result from a native Javascript function (I am in the browser), and conditionally integrate it into a map. I have a function to wrap a native browser call (inspired by Timothy Baldridge's talk on core.async [this video] , approx. 34 min for those interested) : (defn geolocation [] (let [c (chan) cb (fn [e] (put! c (js->clj e)))] (if (exists? js/navigator.geolocation) (.getCurrentPosition js/navigator.geolocation. cb cb) (put! c {:error "Geolocation is not supported"})) c)) I can use it like that : ;; this works (go (.log js/console "RES1 -" (<! (geolocation)))) ;; this too (not sure how to print it though) (go (println "RES2 - "

Cites Alan Thompson · 2016-12 · Stack Overflow · on “Processing Infinite (Lazy) Sequences”

Your problem is tailor-made for clojure.core.async . This code shows the outlines: (ns tst.clj.core (:use clj.core clojure.test) (:require [clojure.core.async :as async] )) ; create a buffer of arbitrary size 99 (any size, even zero, would work) (let [buffer (async/chan 99) ] (async/go ; start sending loop in another thread (while true (Thread/sleep 3000) (let [val (rand-int 5) ] (println "putting:" val) (async/>!! buffer val)))) (while true ; start receiving loop in this thread (println "received:" (async/<!! buffer)))) with output: *clojure-version* => {:major 1, :minor 8, :incremental 0, :qualifier nil} java.version => 1.8.0_111 putting: 4 received: 4 putting: 1 received: 1 putting: 0 rec