Fork me on GitHub
#core-async
<
2018-05-25
>
lxsameer17:05:01

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

noisesmith17:05:05

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

lxsameer17:05:07

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

noisesmith17:05:25

an error happens, but it's async

lxsameer18:05:42

so how people implement back pressure using core.async

noisesmith18:05:55

by not using put!

noisesmith18:05:22

>! and >!! both impose backpressure

lxsameer18:05:10

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

noisesmith18:05:23

parking or blocking

lxsameer18:05:50

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

noisesmith18:05:19

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

noisesmith18:05:42

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

noisesmith20:05:40

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)

noisesmith20:05:23

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

noisesmith20:05:15

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

Logan Powell20:05:15

or should I just pipe promises

noisesmith20:05:36

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?

noisesmith20:05:16

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

noisesmith20:05:37

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 😄

noisesmith20:05:57

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?

hiredman21:05:14

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

noisesmith21:05:27

def inside a go block is a bad idea

hiredman21:05:38

def inside anything is a bad idea

leonoel07:05:21

only a sith deals in absolutes

noisesmith21:05:41

and yeah, make sure you understand clojure / clojurescript

noisesmith21:05:14

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 http://exercism.io tutorials

Logan Powell21:05:38

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

noisesmith21:05:53

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

noisesmith21:05:41

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

noisesmith21:05:50

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?

noisesmith22:05:07

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?

noisesmith22:05:26

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

noisesmith22:05:32

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