Error handling in core.async

Played around using core.async in ClojureScript for coordinating async AJAX requests and app state updates. See this gist for more code and explanation.

(defrecord Controller [state router]
  view/ControllerProtocol
 
  (on-navigation [_ file-id]
    (go
      (try
        (chain
          (<?initialize-state! state)
          (<?set-current-file! state file-id router))
        
        (catch js/Object e
          (println "!!! ERROR - on-navigation - caught"
                   (if (channel-error? e)
                     (str "error from some channel, error data: " (channel-error-data e))
                     (str "js exception: " e)))))))
 
  (on-change-current-file [_ file-id]
    (go
      (try
        ; <? is needed to wait for result or raise an exception
        (<? (<?set-current-file! state file-id router))
 
        (catch js/Object e
          (.error js/console "on-change-current-file exception:" e))))))
Advertisements

One thought on “Error handling in core.async

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s