Curated articles, resources, tips and trends from the DevOps World.
Summary: This is a summary of an article originally published by the source. Read the full original article here →
Cryptography, Programming, and Security Articles For example, if I have a web page that needs to request 7 files from the server before it can show the page, I need to asynchronously fetch all those files at the same time.
the problem is that after starting 3 separate goroutines and yielding execution back to the main thread, there is nothing stopping main() from exiting.
In order to make sure that we wait for all of our functions to complete, but to still allow them to execute at the same time, we use a WaitGroup.
We pass a pointer to the WaitGroup to each goroutine and use the defer keyword to mark a counter done when each goroutine exits.
Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com