Pablo Fernandez
Pablo Fernandez

Reputation: 287450

In ClojureScript, let a go-loop run until it's channel is exausted

A library I'm using, re-frame, uses a go-loop to process events. In a ClojureScript function I'm writing I need to stop and wait until that channel has been exhausted, that is, all events have been processed (including the ones that were generated during the processing of events).

How do I go about it?

A bit of context. I'm writing a library for server side rendering of single page applications and I have mostly in place to run the application in NodeJS, the problem is that I'm doing more or less this:

(defn render-application []
  (re-frame/dispatch [:get-data-needed-to-render])
  (reagent/render-to-string [views/main-view]))

The event handler :get-data-needed-to-render will trigger one or more AJAX requests to the server to get the data needed to render the application, the data needed by reagent/render-to-string.

Upvotes: 1

Views: 368

Answers (1)

skrat
skrat

Reputation: 5562

You can dispatch :data-needed-to-render-ready when :get-data-needed-to-render is finished downloading. Then write a handler for it, which will run (reagent/render-to-string [views/main-view])). And in your main function, the entry point, just dispatch :get-data-needed-to-render.

Upvotes: 1

Related Questions