Hi,
I'm having an Om app, and s sync module that handles remote API calls (this is
not om-sync but same spirits). II need a mechanism where I can cancel previous
requests to the backend API if I have a new request coming. I'm using Google
Closure XhrIo and I know it has an abort method, but the way I'm using it is
that every request just puts results on a channel and the calling code is
listening on a channel something like that:
(defn- get-response [url]
(let [ch (chan 1)
xhr (XhrIo.)]
(events/listen xhr goog.net.EventType.SUCCESS
(fn [_]
(u/put-and-close! ch (t/->AsyncMsg :success (js->clj
(.getResponseJson xhr)
:keywordize-keys true)))))
(events/listen xhr goog.net.EventType.ERROR
(fn [e]
(u/put-and-close! ch (t/->AsyncMsg :error e))))
(.send xhr url "GET")
ch))
(some-calling-function [app-state]
(go
(let [response (< (get-response "some-api-url")]
(assoc-response-to-app-state response app-state))))
AysncMsg is just a record with status and data.
I want to be able to create something to cancel a message, I had written
something with a cancel channel and doing alts on the channels, so if I have a
new request I'll put some message on the cancel channel, but encountered race
conditions and timing issues. I can post a full code example as well, but
wanted to know if someone has implemented something similar in the past and how
they handled it.
--
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.