Clojure Functional Programming & JVM Backend Development · درس

قنوات core.async وكتل Go

إلى جانب refs وatoms، تضيف core.async التزامن بأسلوب CSP إلى Clojure. يعلّمك هذا الدرس القنوات وكتل go وتنسيق العمل غير المتزامن باستخدام عمليات متواصلة.

الدرس 4 من 413 خطوة

قنوات core.async وكتل Go درس مجاني في Clojure Functional Programming & JVM Backend Development على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Clojure Functional Programming & JVM Backend Development، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Clojure Functional Programming & JVM Backend Development 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

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.

البدء مجانًا

تعلم Clojure مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «قنوات core.async وكتل Go» مجاني؟

نعم — نص درس «قنوات core.async وكتل Go» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Clojure Functional Programming & JVM Backend Development، انتقل إلى CoddyKit PRO. تتضمن دورة Clojure Functional Programming & JVM Backend Development 4 دروس في المجموع.

ماذا ستتعلم في «قنوات core.async وكتل Go»؟

إلى جانب refs وatoms، تضيف core.async التزامن بأسلوب CSP إلى Clojure. يعلّمك هذا الدرس القنوات وكتل go وتنسيق العمل غير المتزامن باستخدام عمليات متواصلة. تتمرن على Clojure Functional Programming & JVM Backend Development مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Clojure Functional Programming & JVM Backend Development؟

لا تُشترط خبرة سابقة. Clojure Functional Programming & JVM Backend Development على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «قنوات core.async وكتل Go»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Clojure Functional Programming & JVM Backend Development هذا؟

نعم. كل درس في Clojure Functional Programming & JVM Backend Development يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. Refs وAgents وAtoms لإدارة الحالة
  2. الذاكرة المعاملاتية للبرمجيات (STM)
  3. الوعود والمستقبلات والعمليات غير المتزامنة
  4. قنوات core.async وكتل Go
← العودة إلى Clojure Functional Programming & JVM Backend Development