February 2019
Intermediate to advanced
450 pages
11h 59m
English
To look at the impact of background threads, we will add another feature to the GoMail application—updating the user interface when a new email arrives. To enable this, we must listen to the Incoming channel that our client.EmailServer type defines.
First, we create a function that will handle incoming email. This is simply a wrapper to a new method, appendEmail(*client.EmailMessage), that handles adding new items to the email list. But it must create a wrapping func() and pass it to ui.QueueMain so that the code executes on the correct thread:
func (m *mainUI) incomingEmail(email *client.EmailMessage) { ui.QueueMain(func() { m.appendEmail(email) })}
Then we add a little more code to our main() method to listen for incoming emails ...
Read now
Unlock full access