"The browser does not support threads so neither can core.async."
To expand on that, core.async uses cooperative multitasking, which means you have to give control back every so often so it can schedule other go blocks to be run. Calls like <! will do this while they block (which is why timeout works). On Tue, 25 Aug 2015 at 09:23 Thomas Heller <[email protected]> wrote: > This has nothing to do with core.async or the go macro. If you block the > CPU you will block the UI. The browser does not support threads so neither > can core.async. > > What the timeout achieves is that you give some control back to the > browser so instead of 1sec "blocking" you get 5x200ms blocking. Still far > from 60fps but better than 0. > > If you want to do CPU intensive work without blocking the UI you'll need > to use one or more WebWorkers. You could layer core.async on top of that to > communicate between the Workers and the UI but core.async itself does > nothing in that regard. > > WebWorkers are pretty easy to get going but carry their own set of > drawbacks so it is very dependent on your use case whether they make sense > or not. > > HTH, > /thomas > > > > On Monday, August 24, 2015 at 5:33:48 PM UTC+2, Timothy Pratley wrote: > > I have an issue where work inside a 'go block' is blocking my UI. > > Inserting a (<! (timeout 1)) 'fixes' it. > > > > ** Is there a more idiomatic way? ** > > > > Here is a cut down version built from a fresh template: > > If you run this code, you don't see the thinking deeply countdown, and > you cannot click the other button. > > > > If you uncomment the timeout 1, it works better. > > > > > > > > (defn hello-world [] > > [:div > > [:h1 (:text @app-state)] > > [:button > > {:on-click > > (fn [e] > > (swap! app-state assoc :thinking true :thinking-deeply 5) > > (go > > (while (pos? (:thinking-deeply @app-state)) > > ;(<! (timeout 2000)) > > (apply * (rest (range 10000000))) > > ;(<! (timeout 1)) > > (swap! app-state update :thinking-deeply dec)) > > (swap! app-state dissoc :thinking :thinking-deeply)))} > > "The button!"] > > (when (:thinking-deeply @app-state) > > [:h2 "Thinking deeply " (:thinking-deeply @app-state)]) > > (when (:thinking @app-state) > > [:h2 "Thinking"]) > > [:button "The other button"]]) > > > > Full source code is attached > > > > > > Regards, > > Timothy > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
