From 82fd5c2e56173612491eaaefb7e46dd2fbf161b7 Mon Sep 17 00:00:00 2001 From: Simon Drake <62928647+simondrake@users.noreply.github.com> Date: Mon, 1 Jun 2020 10:43:25 +0100 Subject: [PATCH] content: fix link/improve wording in concurrency-timeouts.article - Fix the `time.After` link so it shows properly - Improve the wording describing the `Query` function, so it's clearer to readers. --- content/concurrency-timeouts.article | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/content/concurrency-timeouts.article b/content/concurrency-timeouts.article index 8237e7d6..0a5c236e 100644 --- a/content/concurrency-timeouts.article +++ b/content/concurrency-timeouts.article @@ -41,7 +41,7 @@ before the timeout is reached. The `timeout` channel will eventually be deallocated by the garbage collector. (In this example we used `time.Sleep` to demonstrate the mechanics of goroutines and channels. -In real programs you should use ` [time.After](https://golang.org/pkg/time/#After)`, +In real programs you should use [`time.After`](https://golang.org/pkg/time/#After), a function that returns a channel and sends on that channel after the specified duration.) Let's look at another variation of this pattern. @@ -65,9 +65,8 @@ It queries each of the databases in parallel and returns the first response it r return <-ch } -In this example, the closure does a non-blocking send, -which it achieves by using the send operation in `select` statement with a `default` case. -If the send cannot go through immediately the default case will be selected. +In this example, a select statement is used within a closure to prevent the channel from blocking. If the result from +`DoQuery` isn't immediately available, the `default` case is selected making the send non-blocking. Making the send non-blocking guarantees that none of the goroutines launched in the loop will hang around. However, if the result arrives before the main function has made it to the receive,