# Buffered Channels

As hinted in previous Chapter, by default channels are not buffered (i.e does not hold value), meaning that connection has to be active with both ends (sending, recieving) being present. Buffered channel allows sent values to buffered (upto its capacity) until reciever recieves it.

This way sender can still enqueue messages in channel, without bothering about reciever being stuck or not attached. Lets look at example with buffer size two

```go
func main() {
    msg := make(chan string, 2)
    msg <- "Hello World"
    msg <- "Hola"
    fmt.Println(<-msg)
    fmt.Println(<-msg)
}
```

In above illustration, channel received first message `"Hello World"` and then while the message was still in the queue, it recieved another message `"Hola"` and recievers were not even defined by then. Buffered channel  can overflow in case buffer is full and we try to assign another value to it, ant throw panic

```go
    msg <- "Hello World"
    msg <- "Hola"
    msg <- "Holaa"            // will panic
    fmt.Println(<-msg)
    fmt.Println(<-msg)
    
    // fatal error: all goroutines are asleep - deadlock!
```

Buffer capacity of a channel can be known by using utility method, provided by Go `cap`&#x20;

```go
cap(msg)
// => 2
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://golang.bagwanpankaj.com/advanced-go/channel-buffering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
