Timeout using Select Statement
This lesson will introduce you to a pattern which uses the `time.After` function in a select statement.
In the previous lesson, we learned how to break out of channel operations in the select statement. Now what if we want to break out of channel communications after a certain period of time?
This will be done using the time.After
function which is imported from the time
package. It returns a channel that blocks the code for the specified duration.
After that duration, the channel delivers the current time but only once.
Let’s have a look at an example using the time.After
function:
Get hands-on with 1400+ tech skills courses.