A channel is used to send and receive data between goroutines.
It provides a safe way to communicate without shared memory.
Channels are created using the make() function.
You must specify the type of data the channel will carry.
Use the <- operator to send data into a channel.
The operation will block until another goroutine is ready to receive.
You can receive data from a channel using the same <- operator.
This will block until data is available.
This example shows sending and receiving data between a goroutine and main.
Channels are blocking by default.
This means sending or receiving will wait until the other side is ready.
Buffered channels allow storing a limited number of values without blocking immediately.
They are created by adding a size to make().
Channels are commonly used to coordinate work between goroutines.
This ensures safe communication and synchronization.
Channels are a core part of Go’s concurrency model.
Be careful with these:
Create a goroutine that sends a number through a channel and print it in main.