Junior — Senior
Parallel loading of URL list with early termination on error
livecode
Task condition
Given an array of strings, each representing a URL. You need to write a function download(urls []string) error that downloads the content of all specified addresses concurrently. If at least one request fails, the function should immediately return that error; if all requests succeed, return nil. Ensure correct operation in a multithreaded environment and implement a mechanism to cancel all other requests upon the first error.
func main() {
_, err := download([]string{
"https://example.com/e25e26d3-6aa3-4d79-9ab4-fc9b71103a8c.xml",
"https://example.com/a601590e-31c1-424a-8ccc-dec5fb35c0f6.xml",
"https://example.com/1cf0dd69-a3e5-4682-84e3-dfe22ca771f4.xml",
"https://example.com/ceb566f2-a234-4cb8-9466-4a26f1363aa8.xml",
"https://example.com/b6ed16d7-cb3d-4cba-b81a-01a789d3a914.xml",
})
if err != nil {
panic(err)
}
}
func download(urls []string) error {
return nil
}