Fork me on GitHub
#core-async
<
2017-02-15
>
hlolli18:02:09

does core.async/thread do anything in cljs/node.js? As a node.js noob Im having diffuculty with a go-loop that I want to be asynchronous, but just blocks the repl when running.

hiredman18:02:21

thread doesn't exist in the clojurescript version of core.async

hiredman18:02:02

if you don't do any channel operations in your go loop it will never yield so other things can run

hlolli18:02:40

ok

(go-loop [old-t 0]
   (when-not (.PerformKsmps csound Csound)
     (let [tick (.GetControlChannel
                 csound Csound "tickcnt" nil)]
       (when-not (= old-t tick)
         (go (>! metro-channel tick)))
       (recur tick))))

hlolli18:02:57

this blocks all further inputs to the repl

hiredman18:02:19

I am not sure how the clojurescript repl works, is metro-channel using a dropping buffer or anything like that?

hlolli18:02:30

a sliding buffer yes

hiredman18:02:59

so that loop is running without anything slowing it down

hlolli18:02:17

it's suppose to be an infinite loop

hlolli18:02:38

so my question may just as well be, how to start infinite loop in node.js without blocking everything 🙂

hiredman18:02:51

if you replaced the go-loop with a something like (fn f [] (async/go .... (f))) that would run f over and over but still yield the thread

hiredman18:02:37

javascript isn't my area of expertise, but you may want to not use a go block at all, and use some kind of scheduled execution facility, I think there is some js function you can call to execute code every N milliseconds sort of thing

hlolli18:02:30

tja jah, ok. 🙂 I need to dig deeper. Im seeing if I can change to node.js for musical creation, so latency involved with timouts could be too much. But .PerformKsmps is in clj a blocking call, it waits until 1 unit of musical time passes before recurcion. So as I type this, I may need to rethink this loop in js world.

hiredman18:02:10

ah, yeah, doing blocking operations in javascript is going to block

hiredman18:02:25

nothing go can do about that, js is single threaded

hlolli18:02:20

yes, just want the illusion of async that core-async offers 🙂

hiredman18:02:14

core.async offers the inverse, the illusion of sync on top of async, if your api is not async, core.async isn't going to do much for you