I recommend using invokeLater to send a fn to Swing to do the rendering.

http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)


If you need Swing to notify the go channel when the rendering is complete,
you can do something like this:

(go
  (let [c (chan)]
    (SwingUtilities/invokeLater (fn [] (do ...stuff.... ) (close! c)))
    (<! c)))

Wrap in a macro if you find yourself doing it a lot:

(go (in-swing-and-wait
       ...stuff...))

Timothy


On Mon, Jul 29, 2013 at 8:44 AM, <eliassona...@yahoo.com> wrote:

> Hi, I'm playing around with core.async a bit.
> Is it possible to put java.awt.Graphics object into a channel and do the
> drawing in a go loop consuming this channel.
> The problem I'm having is that when I consume the channel, core.async has
> switched to another thread. I'm not in the Swing thread anymore.
> Is there a way to stay in the Swing thread while doing this?
>
> This is how I setup the producer:
>
> (defn create-canvas [paint-channel]
>   (proxy [JButton] []
>                  (getPreferredSize [] (Dimension. 300 300))
>                  (paintComponent [g]
>                    (go
>                      (proxy-super paintComponent g)
>                      (>! paint-channel g))))) ;I've tried put! too
>
> Thanks!
> --anders
>
>
>  --
> --
> 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+unsubscr...@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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
-- 
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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to