That code doesn't help much either since there is still no way to tell what 
sess/transformations-cur is.

I'd suggest printing the value before trying to swap! it, I see no reason 
anything in there would confuse core.async.

(defn save-transformation [_] 
  (go (let [trans-name (hel/get-value "transformation-name") 
            [ok _] (<! (hel/post-async->ch "/cvs/save-transformation" 
                                           {:name trans-name 
                                            :data 
@sess/transform-history-cur}))] 
        (if ok
          (do (.log js/console "before swap" (pr-str @sess/transformations-cur))
              (swap! sess/transformations-cur conj {:name "foo-name"}) 
              (h/show-success-message "notification-div" "Transformation 
Saved.")) 
          (h/show-error-message "notification-div" "Could not save 
Transformation. Something went wrong.")))) 

  ;; this immediately executes after the go block starts
  ;; this will most likely happen before (if ok ...)
  ;; if sess/transformations-cur is a set, adding the same obj twice will have 
no effect?
  (swap! sess/transformations-cur conj {:name "foo-name"})) 


Remember that it is async, so if something does something to 
sess/transformations-cur and leaves it in an unusable state you will get 
errors. It all depends on the speed of the subsequent steps and who gets there 
first.

Maybe a simple (add-watch sess/transformations-cur (fn [_ _ _ new] (prn 
[:swapped new])) would help tracking down the issue as well (I assume its an 
Atom?). But CLJS core.async is a lot more fragile than CLJ so it might actually 
be a bug, although the operation is quite simple so I'd suspect some sort of 
ordering issue.

HTH,
/thomas

On Wednesday, December 24, 2014 3:12:07 PM UTC+1, Sven Richter wrote:
> Hi Thomas,
> 
> the code I pasted was maybe a bit misleading.
> 
> Function one:
> (defn save-transformation [_]
>   (go (let [trans-name (hel/get-value "transformation-name")
>             [ok _] (<! (hel/post-async->ch "/cvs/save-transformation"
>                                            {:name trans-name
>                                             :data 
> @sess/transform-history-cur}))]
>         (if ok (do(swap! sess/transformations-cur conj {:name "foo-name"})
>                    (h/show-success-message "notification-div" "Transformation 
> Saved."))
>                (h/show-error-message "notification-div" "Could not save 
> Transformation. Something went wrong."))))
>   (swap! sess/transformations-cur conj {:name "foo-name"}))
> 
> Function two:
> (defn save-transformation [_]
>   (go (let [trans-name (hel/get-value "transformation-name")
>             [ok _] (<! (hel/post-async->ch "/cvs/save-transformation"
>                                            {:name trans-name
>                                             :data 
> @sess/transform-history-cur}))]
>         (if ok (do nil )
>                (h/show-error-message "notification-div" "Could not save 
> Transformation. Something went wrong."))))
>   (swap! sess/transformations-cur conj {:name "foo-name"}))
> 
> Function two works, function one does not. The only difference is when the 
> swap on the cursor happens, either inside the go block (won't work) or 
> outside the go block (does work).
> 
> This is the asnyc code I am calling in both cases:
> 
> (defn post-async->ch [url method content]
>   (let [ch (chan 1)]
>     (ajax/ajax-request
>       {:uri             url
>        :method          method
>        :params          content
>        :format          (ajax/transit-request-format)
>        :response-format (ajax/transit-response-format)
>        :handler         (fn [resp](put! ch resp))})
>     ch))
> 
> The error message indeed seems weird, but everything I tried so far indicates 
> a bug or a missing feature in core.async.
> 
> In the meantime I even refactored my code to remove every core.async bit from 
> the ajax calls and it works as expected then (by working with callbacks 
> instead).
> 
> Best Regards,
> Sven
> 
> Am Mittwoch, 24. Dezember 2014 14:23:35 UTC+1 schrieb Thomas Heller:
> > Cannot say without the rest of the code but I what is in (:transformations 
> > resp)? sorted-set doesn't work if one item doesn't compare to another (eg. 
> > numbers vs maps).
> > 
> > Suppose:
> > 
> > (def a (atom #{}))
> > => (var user/a)
> > (reset! a (into (sorted-set) [1 2 2 2 3]))
> > => #{1 2 3}
> > (conj @a {:name "test"})
> > ClassCastException clojure.lang.PersistentArrayMap cannot be cast to 
> > java.lang.Comparable  clojure.lang.Util.compare (Util.java:153)
> > 
> > Doesn't look like a core.async issue?
> > 
> > 
> > HTH,
> > /thomas
> > 
> > 
> > On Wednesday, December 24, 2014 11:19:04 AM UTC+1, Sven Richter wrote:
> > > Hi,
> > > 
> > > Using the latest core.async (v0.1.346.0-17112a-alpha) updating a sorted 
> > > set results in an error.
> > > 
> > > I have this code:
> > > 
> > > (defn get-transformations []
> > >   (go (let [[ok resp] (<! (h/get-async "/csv/all-transformations"))]
> > >         ;(when ok (reset! sess/transformations-cur (:transformations 
> > > resp)) ;works
> > >         (when ok (reset! sess/transformations-cur (into (sorted-set) 
> > > (:transformations resp))) ;does not work
> > >                  (println (conj @sess/transformations-cur {:name 
> > > "test"}))))))
> > > 
> > > where transformations-cur is a reagent cursor on a reagent atom.
> > > 
> > > The second reset throws this error (Actually the error occurs on updating 
> > > the cursor (conj @sess/transformations-cur {:name "test"})):
> > > Uncaught Error: compare on non-nil objects of different types in 
> > > ioc_helpers:41
> > > 
> > > Are sorted sets not supported?
> > > 
> > > How do others keep there sets / lists sorted in the UI?
> > > 
> > > Of course I could sort it every time I display it, but it seems to be 
> > > more correct to keep it sorted inside the state.
> > > 
> > > Best Regards,
> > > Sven

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to