Fork me on GitHub
#beginners
<
2023-12-26
>
Ryan Martin11:12:27

what are some use cases for core.async? I want to try using it in a project but am not sure what kind of programs it's best for

Ben Sless11:12:18

Anything you can model as a production line can be built using core.async pipelines You can also use them to parallelize transducing operations It's also convenient for asynchronous programming with channels rather than promises and having to enjoy callback hell

jpmonettas12:12:02

@U05PEDP7J85 when working with asynchronous APIs (pretty common in JS land, less common in JVM) you can use it to write synchronous looking code that uses those. On the other side, if you have a synchronous piece of code that you would like to make async for decoupling the caller from the processing parts via buffered channels. If you have something that can benefit from multi-threading you can use core.async also to implement some adhoc actor model, where you spin multiple threads with isolated state and they communicate with each other by sending messages over channels, like producers - consumers.

Ryan Martin15:12:28

Thanks! I think I'll try doing some parallel data processing.

Ben Sless16:12:16

A fun use case is if you're using some queueing system or distributed log like Kafka, then you can process the records in parallel

vlad_poh17:12:54

in clojure can you alias a class like you can a namespace?

Alex Miller (Clojure team)17:12:00

no, if you have same class from different packages, you will need to use the fully-qualified class name for one of them

vlad_poh17:12:44

bummer. Thanks for the quick response!

vlad_poh17:12:16

oh and to other beginners avoid llms. I asked and got a very wrong answer. (ns your-namespace (:import [java.util HashMap] [java.util.concurrent Executors] [java.util.regex Pattern] [http://java.io File] [java.time LocalDate :as Date]))