Fork me on GitHub
#core-async
<
2016-10-06
>
josh.freckleton03:10:20

I just added this to stackexchange's codereview, would you any of you async pros mind glancing at my work, and tell me if I'm doing things idiomatically, or if there's a better way? http://codereview.stackexchange.com/questions/143380/a-simple-async-task-in-clojure Thanks so much!

val_waeselynck07:10:08

(I'm not an authority regarding what's idiomatic, but at least I can suggest improvements)

josh.freckleton13:10:50

@val_waeselynck those were awesome suggestions, thank you, implementing now...

dimovich16:10:20

Hello clojurians

dimovich16:10:00

I need to make "time-buffered" evaluation... so I don't overload with requests some servers...

dimovich16:10:09

Came up with this code

dimovich16:10:54

is this the right approach? Maybe there is some better solutions?

dimovich16:10:37

(timebuff (http/get "some url" ...))

hiredman16:10:28

arguments are evaluated

hiredman16:10:56

so your http/get is happening immediately before timebuff is called, then timebuf is just waiting for a while to give you the result

dimovich16:10:44

so, a macro then...

hiredman16:10:51

or pass a thunk

hiredman16:10:32

I wouldn't structure it that way either

hiredman16:10:51

I would create a loop running on a thread that reads a pair of [thunk result-channel] from an input channel, then does (!!> result-channel (thunk)) then any sleep, then back through the loop

hiredman16:10:07

because the in and out of the loop happens via channels, you can safely use that from inside go blocks, but timebuff has that blocking <!! in it

dimovich18:10:48

what is a "thunk" ? 🙂

hiredman18:10:53

zero argument function

hiredman18:10:07

(fn [] expr)