Fork me on GitHub
#clojure-uk
<
2019-10-10
>
dharrigan04:10:06

Been watching Core Async talk given by Rich at Strangeloop 2013. Very interesting - an area I need to look further into.

seancorfield04:10:52

We use core.async a LOT at work in a couple of apps... but not the apps I work on 😞

dharrigan04:10:42

Is it all channels, or some - dare I say - traditional threads as well?

dharrigan04:10:35

In the talk, Rich mentions (thread.... and then also describes (go...

dharrigan04:10:54

and he makes the distinction between using a (thread... and a (go... block.

dharrigan04:10:41

I realise that using tradtionally instead of tradtional in my comment probably made you say > WAT?

mccraigmccraig06:10:08

what dyu mean @dharrigan "threads as well" ?

dharrigan07:10:46

I think I would do a disservice by trying to explain in my own words, Rich's talk goes into it πŸ™‚

dharrigan07:10:51

I would fail horribly πŸ˜‰

Ben Hammond07:10:16

I've worked in a few projects where folk have gone crazy with core.async

Ben Hammond07:10:27

sure its fun at the time, but

Ben Hammond07:10:35

Please Won't Somebody Think Of The Maintainers

otfrom07:10:57

I've used core.async in web front end stuff (with Om) where I was reasonably happy with it. I used it to create some data pipelines for another thing (which I can't open source directly annoyingly) where I was very happy with it. I liked the way it structured the flow of data and being able to put transducers onto channels and mults to move things to different areas to make different data products made me very happy.

otfrom07:10:51

the data pipeline didn't have any concurrency, but lots of embarrassing parallelism in the different data products, but with lots of partially shared bits of processing

Ben Hammond07:10:16

I think its killer feature is backpressure

Ben Hammond07:10:38

you can bring the whole line to a halt if you cannot keep up

Ben Hammond07:10:51

rather than building up a memory aneurysm that will pop

Ben Hammond07:10:13

sometimes you'd rather have an OOM just now

Ben Hammond07:10:24

than wonder in 5 minutes why its ground to a halt

Ben Hammond07:10:06

(and of course tracing which bit of a long pipeline has ground to a halt can be a right pain in the arse)

dharrigan07:10:43

I think, for me, at the moment, my understanding is the intention - if my program is the one that is initiating a call to an external resource (db/web), then putting that call in a thread seems okay. If, on the other hand, I want my program to react to external events, i.e., listen for incoming connections, things coming from external systems, then putting that in go blocks and into channels is better

dharrigan07:10:05

For example, I have this, which I'm just trying out to see if it works for me:

dharrigan07:10:08

(future
   (loop []
     (when-let [vehicle-ids (find-vehicle-ids-with-missing-vrns)]
       (when-let [vehicles (vehicle-client vehicle-ids)]
         (update-vehicles-with-vrn-and-vin vehicles)))
     (Thread/sleep 10000)
     (recur))))

dharrigan07:10:35

the find-vehicle... and vehicle-client are 1. a database lookup and 2. a REST call.

dharrigan07:10:38

So, putting that into a thread (future) that just ticks around in the background whilst my program gets on with other stuff (consuming from kafka and doing calculations) feels okay.

jasonbell07:10:00

The Thread/sleep would concern me most of all. What’s the fallback if > 10000ms?

mccraigmccraig07:10:20

@ben.hammond @dharrigan the stream-processing model is just very simple and explicit - backpressure and and buffer-size between them give you a remarkable amount of control

dharrigan07:10:12

That's okay (I believe) as the update doesn't have to update all vehicles in one go, a next loop around will pick up missing details again and fill in missing - it keeps going - if it fails (per loop), not an issue.

dharrigan07:10:35

find-vehicle and vehicle-client are blocking operations

Ben Hammond08:10:36

> between them give you a remarkable amount of control very much agree, but requires experience and self-control to use wisely comes back to running with sharp tools

dharrigan08:10:50

I'm still very much learning how to use πŸ™‚

dharrigan08:10:59

slowly slowly

Ben Hammond08:10:56

if

(vehicle-client vehicle-ids)
tolereated a nil vehicle-ids input, by returning an immediate nil response you could collapse one of your (when-let clauses just sayin'

dharrigan08:10:27

thanks! πŸ™‚

dharrigan08:10:47

Always good to improve code

dharrigan08:10:02

Actually replaced the when-let with some->

πŸ‘ 4
mccraigmccraig09:10:04

you could separate out the timer/loop logic and any i/o logic from any data transformation logic too - then it would get more testable

dharrigan09:10:49

thanks πŸ™‚

Ben Hammond10:10:29

> Mr Trump said: "The woman was driving on the wrong side of the road, and that can happen. > > "You know, those are the opposite roads, that happens. I won't say it ever happened to me, but it did.

flefik11:10:36

We were nearly in a full frontal crash on a small country road in the Cotswolds last year. An American elderly couple came around the corner in their rental car doing ~50mph, on the right (wrong) side of the road and nearly crashed into us. We both stood on the breaks and managed to avoid a crash with maybe a metre to spare. He apologised profusely of course, but I was not happy. I glared and tutted at him to his face.

folcon11:10:01

Morn =)…

flefik11:10:36

We were nearly in a full frontal crash on a small country road in the Cotswolds last year. An American elderly couple came around the corner in their rental car doing ~50mph, on the right (wrong) side of the road and nearly crashed into us. We both stood on the breaks and managed to avoid a crash with maybe a metre to spare. He apologised profusely of course, but I was not happy. I glared and tutted at him to his face.

dharrigan12:10:34

We forgot to put 50p in the meter this morning, just had a powercut on our floor

dharrigan12:10:41

journaled filesystems ftw!

Ben Hammond12:10:57

how long does 50 pence last you?

practicalli-johnny13:10:10

If it’s a Brexit 50 pence then it only lasts 5% of a real 50p

πŸ˜‚ 4
dharrigan13:10:42

not long enough πŸ™‚

Ben Hammond13:10:21

what happens to all the 50 pences? does that meter have to get emptied manually? is there vacuuum tube directly to the centre of the earth, where they get melted down?

Ben Hammond13:10:46

do they drop out into a bucket so you reuse them?

Ben Hammond13:10:41

can you take a fret saw and hollow them out?

Ben Hammond13:10:13

cut out a 20 pence stencil from inside the 50 pence

Ben Hammond13:10:18

hehe. TopCat style, attach some thin wire to the coin so that you can retrieve it from the meter

thomas14:10:51

πŸ‘‹ @emilien and @ataggart

πŸ‘‹ 8
πŸ™ 4
Wes Hall22:10:51

@ben.hammond Re: diplomat crash. I do think it's fairly instructive to consider how you (general sense) would handle this situation. I think it is all too easy to expect saintly behaviour from people but it can't be that easy to volunteer for a prison sentence. I am sure any defence lawyer, paid to keep their client out of prison, even if they are guilty, even if they are maliciously guilty (not applicable here), would see the diplomatic immunity loophole and say, "why are you still here?!". Trump obviously can't wave diplomatic immunity, and neither would Obama (or Clinton had she won). Far too "precedent setting". Perhaps for premeditated murder, but they obviously wont risk jeopardising the notion of diplomatic protection over this (even if it should be 'jeopardised'). To my mind we are in this odd situation where the woman wont be going to prison no matter what happens, because honestly, if she came back, fully of her own accord to "face the music" when she didn't have to, I'd call that an act of fairly extreme selfless high morality, and suggest that she should probably be treated quite leniently in response. If she doesn't come back, then... well... As it turns out, the criminal justice system only really makes sense when defendant don't really have a, "nah, rather not!", option.

πŸ‘ 8