I am trying to bring up a window with a Label in it, asynchronously receive a message of some sort (say, originating from a HTTP request), and based on that message update the label. For example:
Bring up window with label in it saying "Waiting for message"
Send message saying "new message"
Label now says "new message"
The Actor model makes good sense to me in terms of passing in messages. Sending in a message to instruct the actor to perform an action seems fairly intuitive, and indeed I was able to set up a proof of concept that had it echo the message it received.
However, the problem I am having is with updating the label. All the Actor examples I could find on here involve using echo rather than, say, modifying a Widget - so while I was able to get an Actor example up and running that would echo the message, I have not been able to do the same for a label.
I think the problem I am having is that - according to other discussions I have read - Window.open blocks execution on the current thread. This is a problem because I can only pass serialized messages between the current thread and other threads, meaning I cannot possibly (as far as I can tell) pass the current label to an Actor in order to change it.
All I can do is serialize the label, pass a serialized copy to the Actor, and then have the actor do something to that copy - which of course will not update the original. Or I can change the label via events, but I'm not aware of an event that fires when a message is received from another thread.
So is there some way to do what I'm trying to do?
KevinKelleySun 25 Apr 2010
Look at examples/fwt/clock.fan for an example of this. The key point is, since the UI is always going to be single-threaded, your other threads (actors) have to communicate with the UI by sending messages, which can only be const.
So if you have your UI element register itself somewhere as being the handler for a kind of message, then later you can use Desktop.callAsync to have the UI thread execute a function that, looks up the handler and calls UI methods on it.
rfeldman Sun 25 Apr 2010
I am trying to bring up a window with a Label in it, asynchronously receive a message of some sort (say, originating from a HTTP request), and based on that message update the label. For example:
The Actor model makes good sense to me in terms of passing in messages. Sending in a message to instruct the actor to perform an action seems fairly intuitive, and indeed I was able to set up a proof of concept that had it echo the message it received.
However, the problem I am having is with updating the label. All the Actor examples I could find on here involve using echo rather than, say, modifying a Widget - so while I was able to get an Actor example up and running that would echo the message, I have not been able to do the same for a label.
I think the problem I am having is that - according to other discussions I have read - Window.open blocks execution on the current thread. This is a problem because I can only pass serialized messages between the current thread and other threads, meaning I cannot possibly (as far as I can tell) pass the current label to an Actor in order to change it.
All I can do is serialize the label, pass a serialized copy to the Actor, and then have the actor do something to that copy - which of course will not update the original. Or I can change the label via events, but I'm not aware of an event that fires when a message is received from another thread.
So is there some way to do what I'm trying to do?
KevinKelley Sun 25 Apr 2010
Look at
examples/fwt/clock.fan
for an example of this. The key point is, since the UI is always going to be single-threaded, your other threads (actors) have to communicate with the UI by sending messages, which can only be const.So if you have your UI element register itself somewhere as being the handler for a kind of message, then later you can use
Desktop.callAsync
to have the UI thread execute a function that, looks up the handler and calls UI methods on it.