Day 2: Multiple Channels and IO
Today weâll see how core.async makes asynchronous IO both simpler and easier to understand. But before then, weâll look at a feature weâve not yet seenâââhandling multiple channels at a time.
Handling Multiple Channels
So far weâve dealt only with a single channel at a time, but thereâs no reason we have to restrict ourselves to doing so. The alt! function allows us to write code that can deal with more than one channel:
â | channels.core=>â (def ch1 (chan))â |
â | #'channels.core/ch1 |
â | channels.core=>â (def ch2 (chan))â |
â | #'channels.core/ch2 |
â | channels.core=>â (go-loop []â |
â | #_=>â (alt!â |
â | #_=>â ch1 ([x] (println "Read" x "from channel 1"))â |
â | #_=>â ch2 ([x] ... |
Get Seven Concurrency Models in Seven Weeks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.