Fork me on GitHub
#core-async
<
2020-05-12
>
Ben Sless09:05:39

I'm trying to translate the examples from https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf to core.async. its been smooth sailing until I tried translating factorial (4.2)

;; [fac( i: 1..limit)::
;;  * [n:integer;fac(i - 1)?n ->
;;     [n = 0 -> fac(i - 1)!1
;;      || n > 0 -> fac(i + 1)!n- 1;
;;         r:integer;fac(i + 1)?r;fac(i - i)!(n * r)
;;      ]
;;    ]
;;      || fac(0)::USER
;;  ]
Anyone has an idea about how to translate & use it?

Ben Sless09:05:47

nvm, figured it out:

otfrom09:05:09

is there a good example anywhere of how onto-chan! or onto-chan!! should be used with blocking things like reading from a file?

Alex Miller (Clojure team)12:05:44

I’m not sure either is actually the best option if reading from a file, but you could use onto-chan!! if you had a lazy-seq that was reading line by line

otfrom13:05:21

@alexmiller what I've been doing atm is reading from a file line by line and then just putting the lines on the channel and doing that in a thread. Most of my core.async stuff is reading files, scrubbing them, and then sending them through different pipelines to produce lots of different results

otfrom13:05:48

so after the initial bit of reading, there isn't anything blocking until the end of all processing

Alex Miller (Clojure team)13:05:09

well everytime you read from the file, that's potentially blocking

Alex Miller (Clojure team)13:05:14

so if you were doing that in a lazy seq, you could use onto-chan!! (which will use a thread to read from the lazy seq and push into the channel)

Alex Miller (Clojure team)13:05:37

but that's exactly what you're already doing

Alex Miller (Clojure team)13:05:16

the important thing is that you should not use onto-chan or onto-chan! for this b/c they use a go loop and you're doing potentially blocking io

otfrom13:05:33

ok, that fits with my understanding. When doing blocking things, do the blocking thing with a thread, or using a separate blocking happy threadpool (like pipeline-blocking)

otfrom13:05:52

is it a reasonable thing to pass a seq or vec of filenames to pipeline blocking to take advantage of parallel processing offered by pipeline-blocking?

otfrom13:05:21

that gives me a good pattern to follow then

bfay19:05:15

Posted an issue last week about some worker threads that I had doing a recur inside of an alt!!, they were having an issue after a few days. Turns out I'm just a dummy and I had an if statement where the worker was only recurring in the else branch. My workers were dying because I just messed up the code, fortunately had nothing to do with core async or alt!!