Clojure Functional Programming & JVM Backend Development · Ders

core.async Kanalları ve Go Blokları

Ref'ler ve atomların ötesinde core.async, Clojure'a CSP tarzı eşzamanlılık getirir. Bu derste kanalları, go bloklarını ve iletişim kuran süreçlerle eşzamansız çalışmayı koordine etmeyi öğreneceksiniz.

4. ders / 413 adım

core.async Kanalları ve Go Blokları, CoddyKit'te ücretsiz bir Clojure Functional Programming & JVM Backend Development dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Clojure Functional Programming & JVM Backend Development öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Clojure Functional Programming & JVM Backend Development kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why core.async

Atoms and refs manage shared state. core.async manages communication between independent processes using channels, inspired by CSP.

Requiring the Library

Pull in the core functions you will use.

(require '[clojure.core.async :as a
           :refer [chan go >! <! <!! >!!]])

Creating a Channel

A channel is a queue that processes use to hand off values. Create one with chan.

(def c (chan))
; an unbuffered channel

Go Blocks

A go block runs its body asynchronously on a thread pool, parking instead of blocking at channel operations.

(go (println "running asynchronously"))

Putting and Taking

Inside a go block, >! puts a value and <! takes one. Both park until the other side is ready.

(let [c (chan)]
  (go (>! c 42))
  (go (println "got" (<! c))))

Blocking Variants

Outside go blocks, use the double-bang forms >!! and <!!, which block the real thread. Useful at the REPL or in main.

(let [c (chan)]
  (go (>! c "hello"))
  (println (<!! c)))

Buffered Channels

Give a channel a buffer so puts do not park until the buffer is full. This decouples fast producers from slower consumers.

(def c (chan 10))
; up to 10 values can sit in the buffer

Selecting With alts!

alts! waits on several channels at once and proceeds with whichever is ready first, enabling timeouts and racing.

(go
  (let [[v ch] (a/alts! [c (a/timeout 1000)])]
    (println "got" v "from" ch)))

Closing Channels

Closing a channel signals no more values. Takes then return nil, which consumers use as a stop signal.

(a/close! c)
; subsequent <! returns nil

Pipelines of Processes

Wire go blocks together with channels to form a pipeline: each stage takes from one channel, transforms, and puts onto the next. State stays local to each process.

Channels vs Atoms

Use atoms/refs for shared mutable state; use channels to coordinate the flow of work between processes. They solve different problems and often combine.

Quick Check

Test your core.async knowledge.

Recap

You learned channels, go blocks, parking puts/takes, blocking variants, buffers, alts! for selection and timeouts, closing channels, and how channels complement atoms and refs.

Başlamak ücretsiz

Yapay zeka eğitmeniyle Clojure öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“core.async Kanalları ve Go Blokları” dersi ücretsiz mi?

Evet — “core.async Kanalları ve Go Blokları” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Clojure Functional Programming & JVM Backend Development kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Clojure Functional Programming & JVM Backend Development kursu toplamda 4 dersten oluşur.

“core.async Kanalları ve Go Blokları” dersinde ne öğreneceğim?

Ref'ler ve atomların ötesinde core.async, Clojure'a CSP tarzı eşzamanlılık getirir. Bu derste kanalları, go bloklarını ve iletişim kuran süreçlerle eşzamansız çalışmayı koordine etmeyi öğreneceksiniz. Clojure Functional Programming & JVM Backend Development ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Clojure Functional Programming & JVM Backend Development öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Clojure Functional Programming & JVM Backend Development, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“core.async Kanalları ve Go Blokları” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Clojure Functional Programming & JVM Backend Development dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Clojure Functional Programming & JVM Backend Development dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Durum için Refs, Agents ve Atoms
  2. Yazılımsal İşlemsel Bellek (STM)
  3. Promise'ler, Future'lar ve Eşzamansız İşlemler
  4. core.async Kanalları ve Go Blokları
← Clojure Functional Programming & JVM Backend Development Sayfasına Dön