Fork me on GitHub

Hey, if I have a handler that looks something like this:

(defn my-handler [db [_ new-value]]
  (re-frame/dispatch [:something])
  (assoc db :breakfast new-value))
…can I assume in the body of the :something handler that (:breakfast db) will equal new-value? Or is it non-deterministic whether the :something handler or the (assoc) will be executed first, because of asynchrony?


I’m pretty sure that the dispatch won’t be run until the current handler has completed


I had a similar question yesterday


If you decided to park inside a handler in a core.async go block then all bets are off though


it is async


Well, dispatch is going to be called because it's just a function. Inside dispatch :something is going to be put! onto the event-chan. Since there is no matching reader at the moment that happens, the put! won't take place immediately and will be queued up and the call to dispatch will return, the rest of your handler code will get executed, and then at some point in the future the value that you dispatched will get handled.


Cool, thanks for the explanations everyone


@meow: even if there was a matching reader I wouldn’t expect that part to be run until the current handler had finished.