Fork me on GitHub

hey folks, what's best way to implement timeout for put operation ?


put! is async, but with alt! or alt!! etc. you can have a timeout for >! or >!!


what happens to put! if the buffer is full and there is no taker ?


an error happens, but it's async


so how people implement back pressure using core.async


by not using put!


>! and >!! both impose backpressure


hmm i don't get it exactly how. by parking only ?


parking or blocking


if the number of >! increases, we're going to end up with lots of parked put operations


and for each parked >!, you know the next line of code isn't running


as long as you aren't doing something stupid like firing up a new thread for every input, that's backpressure

Logan Powell20:05:19

👋 Hi everyone! I'm venturing into the land of core.async + cljs-ajax does anyone have any reference guides that can help a newb like me? I'm having a hard time finding something in the Googlies


first question is if you even need or want core.async, I know that cljs-ajax imposes that but that doesn't mean you shouldn't evaluate the question

Logan Powell20:05:35

Hi @noisesmith great to see you again! I've been using js promises and... well... I heard the devx of channels is bettah

Logan Powell20:05:00

+ I want to sharpen my core.async skills (of which now I have 0)


yeah, just making sure it's an intentional choice, since core.async tends to take over and impose some quixotic limitations

Logan Powell20:05:24

well, I have to do a LOT of async stuff on this project I'm working on (talking to and coordinating a number of different APIs), so I was hoping that coordination would be easier with core.async


yes, that is what it's for, so it sounds like a good fit

Logan Powell20:05:15

or should I just pipe promises


in cljs, core.async is going to be a nicer experience. I would check out the core.async intro - in cljs you don't have the blocking operations, but you can put put! and take! into callback code, and put normal code into the callbacks that put! and take! accept

Logan Powell20:05:38

as a bonus, I heard I can use all the sequential goodies on channels (transducers, reducers, etc.)

Logan Powell20:05:32

I'll brush up on the code in the walkthrough is there anything that combines cljs-ajax with core.async?


you really shouldn't need that beyond knowing that take! and put! can be called in a callback, and in turn they take a callback arg each


that's your "glue" that lets you transfer between core.async world and normal world

Logan Powell20:05:53

alrighty... I'm so used to complexion with javascript libraries, I'm not used to thinks being straight forward like that 😄


there's a lot of complexity to core.async itself, and it can take a while to get used to thinking about the interface between async world and non-async world as part of control flow, but the mechanics are that simple at the bottom of it

Logan Powell21:05:13

When using go blocks, do I have to do everything inside the go block like with promises or can I store something from one go block into a def and using it separately?


you may want to start with a general clojure tutorial before diving in to core.async


def inside a go block is a bad idea


def inside anything is a bad idea


only a sith deals in absolutes


and yeah, make sure you understand clojure / clojurescript


I'll grudgingly allow def inside let sometimes, if let is at the top level

Logan Powell21:05:16

haha, I have dipped my toes in clojure(script) a bit... some tutorials

Logan Powell21:05:38

sorry, not def inside a go, but a go inside a def


go returns a channel that delivers a value if/when go exits

Logan Powell21:05:22

I've also read most of "Structure and Interpretation of Computer Programs" I've never learned so much from a programming book

Logan Powell21:05:15

ok, so I can pull a value out of a go and return it from a defand use it later

Logan Powell21:05:48

that's what I was hoping, to write async code as if it were happening in lexical order


the code inside go is async and also lexically ordered local to that block, yes


the points of asynchrony are the channel ops

Logan Powell21:05:20

thank you guys for putting up with me... let me get my feet wet on the guide you shared... I'll be back!

Logan Powell22:05:17

So, I can't exactly use the walkthrough... it's written for clojure and cljs.core.async doesn't like the examples 😄

Logan Powell22:05:23

is there a better one for cljs?

Logan Powell22:05:26

it surprises me that docs aren't easier to find... it's like *years* old now, right?


the differences should be pretty simple, why not do the examples in clojure then look at the differences between the cljs and clj core.async versions afterward?


there's just some functions in core.async that make no sense without real threads

Logan Powell22:05:50

Ok, that seems reasonable. I'm just surprised that there are seemingly no docs that chart the differences/gotchas between the two


it's a small list - iirc it's only thread and things that end in !! that don't exist in cljs, any other differences have to do with how macros are used in cljs

Logan Powell22:05:16

thank you @noisesmith patient as always