Learn how to use select to receive and send on and to multiple channels. Discover how you can implement timeouts using select the func After function from the time package.
- [Instructor] The built-in select function…allow us to work with several channels together.…Every time a channel with selecting on…become free, either for sending or receiving,…you'll do an action on this channel.…Let's have a look.…We'll create two channels, channel one and channel two.…And then we run a function that sends a value…to channel one, and now we can do a select.…The select statement is select,…then the curly braces, and then,…a case for every channel that you'd like to select on.…
In our case, we expect value from channel one,…and we print out that we got the value…from channel one, and another case,…we get the value from channel two,…and we print that we got the value from channel two.…Let's save it and run it.…Go run select dot go, and we see…that we got 42 from channel one.…One of the common uses for select…is to implement timeouts.…So we're going to make a channel,…and then create a function that sleeps…for 100 milliseconds, and then sends a value on the channel.…
And then we do a select.…One case, we get the value from the output channel,…
- Go basic types, conditionals, and loops
- Go functions
- Object-oriented programming with Go
- Error handling
- Concurrent programming with channels
- Testing and project management
- Networking with JSON and HTTP
Skill Level Beginner
Programming Foundations: Fuzzy Logicwith Erin Colvin41m 50s Intermediate
Getting started1m 34s
1. Getting Started
2. Go Basics
5. Error Handling
7. Project Management
Next steps1m 12s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.