Background processing

Image processing, even just loading the images to be viewed, is a CPU-intensive task, so if we open a directory with a lot of pictures, the application will be very slow to load. We can fix this delay by moving our image loading to work in the background while we load the user interface. Thankfully, creating new threads for asynchronous processing is very simple with Go (as we explored in Chapter 3, Go to the Rescue!), but we also need to ensure that the user interface is updated accordingly.

To delay the loading of images until there is processing power available, we can replace uses of loadImage() with a replacement asyncImage type that will handle the heavy lifting. The main image loading code will be moved into a ...

Get Hands-On GUI Application Development in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.