FAQ
I'm trying to use cljs.core.async to convert async code to synchronous,
I've hit a problem chaining some calls. I'm getting a runtime state machine
problem, here is a test case for the issue:

(defn td [id t]
(let [c (chan)]
(window/setTimeout (fn [] (go (>! c (name id)))) t)
c
))

(defn tdw [id t]
(go
(let [id2 (<! (td id 500))
c (chan)]
(window/setTimeout (fn [] (go (>! c id2))) t)
(<! c)
)))

(defn start []
(let [p (fn [v] (.debug js/console (str "v: " v)))]
(go
(p (<! (td :1 1000)))
(p (<! (td :2 1)))
(p (<! (tdw :3 200)))
)))

The output is :
v: 1
v: 2

    1. Uncaught ReferenceError: state_machine__5113__auto____$1 is not
    defined


tdw fails in its setTimeout callback.
Is this a legal use case? Have I made a fundamental mistake?

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tassilo Horn at Jul 16, 2013 at 7:58 am

    Mike Longworth writes:

    I'm trying to use cljs.core.async to convert async code to
    synchronous, I've hit a problem chaining some calls. I'm getting a
    runtime state machine problem, here is a test case for the issue:
    Since the go macro transforms its body, you cannot have function defs
    using <!/>! internally in it. Likewise, you cannot call functions from
    inside it that use <!/>! cause those calls would be invisible to the
    macro.

    These limitations are discussed by Rich at the latest think relevance
    podcast.

       http://thinkrelevance.com/blog/2013/07/10/rich-hickey-and-core-async-podcast-episode-035

    Bye,
    Tassilo

    --
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
    ---
    You received this message because you are subscribed to the Google Groups "Clojure" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Mike Longworth at Jul 16, 2013 at 11:21 am
    Thanks Tassilo,
       As you point out, if I move the nested function outside the go then the
    problem is fixed.
    This test case is only a simplification of the original code so I can't do
    this in my actual code however after much head scratching I now understand
    the purpose of take! and it addresses my issue:

    test case solution:

    (defn tdw2 [id t]
    (let [id2 (go (<! (td id 500)))
    c (chan)]
    (window/setTimeout (fn [] (go (>! c (<! id2)))) t)
    c
    ))

    Required solution:
    (defn tdw [id t]
    (let [c (chan)]
    (take! (td id 500) (fn [id2] (window/setTimeout (fn [] (go (>! c
    id2))) t)))
    c
    ))
    --
    --
    You received this message because you are subscribed to the Google
    Groups "Clojure" group.
    To post to this group, send email to clojure@googlegroups.com
    Note that posts from new members are moderated - please be patient with your first post.
    To unsubscribe from this group, send email to
    clojure+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/clojure?hl=en
    ---
    You received this message because you are subscribed to the Google Groups "Clojure" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupclojure @
categoriesclojure
postedJul 16, '13 at 7:43a
activeJul 16, '13 at 11:21a
posts3
users2
websiteclojure.org
irc#clojure

2 users in discussion

Mike Longworth: 2 posts Tassilo Horn: 1 post

People

Translate

site design / logo © 2022 Grokbase