Non-Blocking Channel Operations | Challenge

GoGoBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

This challenge aims to test your understanding of non-blocking channel operations in Golang. You will be required to implement non-blocking sends, receives, and multi-way selects using the select statement with a default clause.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL go(("`Go`")) -.-> go/ConcurrencyGroup(["`Concurrency`"]) go/ConcurrencyGroup -.-> go/channels("`Channels`") subgraph Lab Skills go/channels -.-> lab-15411{{"`Non-Blocking Channel Operations | Challenge`"}} end

Non-Blocking Channel Operations

The problem to be solved in this challenge is to implement non-blocking channel operations using the select statement with a default clause.

Requirements

  • Implement a non-blocking receive on a channel using the select statement with a default clause.
  • Implement a non-blocking send on a channel using the select statement with a default clause.
  • Implement a multi-way non-blocking select using the select statement with multiple case clauses and a default clause.

Example

$ go run non-blocking-channel-operations.go
no message received
no message sent
no activity

Summary

In this challenge, you learned how to implement non-blocking channel operations using the select statement with a default clause. You implemented a non-blocking receive, a non-blocking send, and a multi-way non-blocking select.

Other Go Tutorials you may like