Gowut newbie question: Updating a GUI element after a delay

81 views
Skip to first unread message

Carl Menezes

unread,
Jun 19, 2013, 5:00:01 PM6/19/13
to gowebui...@googlegroups.com
I'm trying to write a little web app that is very similar to the command line terminal, but that I can use to analyze data interactively.
The window only contains 2 text boxes - one at the bottom (the command box) and the other (the output box) that takes up the rest of the screen.

Right now, let's say I issue a command to load a ton of files into memory. "load <dir>"

In the background, a goroutine actually does the work and writes the text output (when its ready) to a string channel which is read from.
I have a display goroutine that reads from that channel and sets the text on the display text box.

My problem is that the display text box only updates the next time an event from the command text box comes in.

In other words, I issue a command in one text box. After a delay, the result is ready and I would like to make the other text update its contents.

How do I accomplish this? 


András Belicza

unread,
Jun 19, 2013, 5:39:23 PM6/19/13
to Carl Menezes, gowebui...@googlegroups.com
There is a Timer component which can generate timed events once or repeatedly. At each timed event there registered listeners are called on the server side where you can do whatever you want, including updating components.
Here's the doc of the Timer component:

Timer interface defines a component which can generate a timed event or a series of timed events periodically.
Timers don't have a visual part, they are used only to generate events. The generated events are of type ETYPE_STATE_CHANGE.
Note that receiving an event from a Timer (like from any other components) updates the last accessed property of the associated session, causing a session never to expire if there are active timers on repeat at the client side.
Also note that the Timer component operates at the client side meaning if the client is closed (or navigates away), events will not be generated. (This can also be used to detect if a Window is still open.)

Check out the included Showcase of Features application which also has a page demonstrating the Timer:

Reply all
Reply to author
Forward
0 new messages