Sobes.tech
Junior — Middle

Have you worked with goroutines in your projects?

sobes.tech AI

Answer from AI

Yes, I have worked with goroutines in Go projects. Goroutines allow functions to run concurrently, which is convenient for handling multiple tasks simultaneously without the complexities of threads.

For example, to run multiple server requests in parallel, you can launch goroutines:

func fetchData(url string) {
    // code to fetch data
}

func main() {
    urls := []string{"http://example.com", "http://example.org"}
    for _, url := range urls {
        go fetchData(url) // launch goroutine
    }
    // wait for goroutines to finish, e.g., using sync.WaitGroup
}

Using goroutines helps efficiently utilize resources and simplifies asynchronous programming.