{"id":826,"date":"2026-10-09T11:00:00","date_gmt":"2026-10-09T05:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/"},"modified":"2026-11-29T01:29:29","modified_gmt":"2026-11-28T19:59:29","slug":"go-channel-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/","title":{"rendered":"Go Channel Programs with Output: Buffered, select and Pipelines"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go channel programs let goroutines send values to each other safely, without shared variables or locks. Go&#8217;s motto is &#8220;do not communicate by sharing memory; share memory by communicating&#8221;, and channels are how you do it. In this post, you will write fourteen channel programs with their exact output and the logic explained in comments, including producer-consumer, ping-pong, pipelines and timeouts with <code>select<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should first read our <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutine-programs\/\">Go goroutine programs<\/a>, because every channel connects goroutines. For the theory, see <a href=\"https:\/\/smitabharat.com\/blog\/go-channels-examples\/\">Go channels explained with examples<\/a> and the <a href=\"https:\/\/smitabharat.com\/blog\/go-select-statement\/\">Go select statement<\/a>. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Channel Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go channel programs use a channel, which is a typed pipe between goroutines. One goroutine sends with <code>ch &lt;- value<\/code>, and another receives with <code>value := &lt;-ch<\/code>. An unbuffered channel makes the sender and receiver meet at the same moment, while a buffered channel has room for a few values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a channel as a pass-through window between a kitchen and a dining room. The cook puts a plate in the window, and the waiter takes it out. With no shelf (unbuffered), the cook waits until the waiter takes the plate. With a shelf for three plates (buffered), the cook can put up to three plates before waiting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Channel Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Channels are the main way goroutines work together. For example, a web scraper sends pages to a parser, a job queue sends tasks to workers and a server uses a channel to signal shutdown. So Go channel programs are one of the most tested areas in Go interviews.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Hand-off:<\/strong> pass work and results between goroutines.<\/li>\n\n\n<li><strong>Signals:<\/strong> tell goroutines to stop by closing a channel.<\/li>\n\n\n<li><strong>Timeouts:<\/strong> give up on slow work with <code>select<\/code> and <code>time.After<\/code>.<\/li>\n\n\n<li><strong>Interviews:<\/strong> deadlocks, closed channels and producer-consumer are classic questions.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Channel Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A send blocks until there is space or a receiver. A receive blocks until a value arrives or the channel is closed. When the sender is finished, it closes the channel, and a <code>for range<\/code> loop on the receiver side stops after the last value.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-1024x640.png\" alt=\"Go channel programs diagram showing a producer sending values through a channel to a consumer\" class=\"wp-image-824\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The producer sends values into the channel, the consumer receives them in order, and close tells the consumer that no more values are coming.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below sums up channel operations.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operation<\/th><th>Syntax<\/th><th>Behaviour<\/th><\/tr><\/thead><tbody><tr><td>Create unbuffered<\/td><td>make(chan int)<\/td><td>Send waits for a receiver<\/td><\/tr><tr><td>Create buffered<\/td><td>make(chan int, 3)<\/td><td>Send waits only when full<\/td><\/tr><tr><td>Send<\/td><td>ch &lt;- v<\/td><td>Panics if channel is closed<\/td><\/tr><tr><td>Receive<\/td><td>v := &lt;-ch<\/td><td>Gets zero value after close<\/td><\/tr><tr><td>Receive with ok<\/td><td>v, ok := &lt;-ch<\/td><td>ok is false after close and empty<\/td><\/tr><tr><td>Close<\/td><td>close(ch)<\/td><td>Only the sender should close<\/td><\/tr><tr><td>Range<\/td><td>for v := range ch<\/td><td>Stops after close<\/td><\/tr><tr><td>Send-only type<\/td><td>chan&lt;- int<\/td><td>Function can only send<\/td><\/tr><tr><td>Receive-only type<\/td><td>&lt;-chan int<\/td><td>Function can only receive<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Go Channel Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These first Go channel programs show sending, receiving and closing. Read the comments in each program, because they explain every new piece of syntax.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Send and Receive with an Unbuffered Channel<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ make creates a new channel that carries string values.\n    \/\/ It is unbuffered, so the sender and the receiver must meet.\n    message := make(chan string)\n\n    \/\/ \"go\" runs this small function in a new goroutine.\n    go func() {\n        message &lt;- \"order #501 packed\" \/\/ &lt;- sends a value into the channel\n    }()\n\n    \/\/ &lt;-message waits here until the goroutine sends a value.\n    received := &lt;-message\n    fmt.Println(received)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>order #501 packed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how it works. First, <code>make<\/code> creates the channel. Then the goroutine sends a string, and <code>main<\/code> waits on <code>&lt;-message<\/code> until that string arrives. So the program never exits before the goroutine has done its job.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Buffered Channel with len and cap<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ The second argument 3 gives the channel room for 3 values.\n    queue := make(chan string, 3)\n\n    \/\/ No goroutine is needed here: a send only waits when the buffer is full.\n    queue &lt;- \"Asha\"\n    queue &lt;- \"Ravi\"\n\n    \/\/ len is how many values are waiting, cap is the total room.\n    fmt.Println(\"len:\", len(queue), \"cap:\", cap(queue))\n\n    fmt.Println(&lt;-queue) \/\/ values come out first in, first out\n    fmt.Println(&lt;-queue)\n    fmt.Println(\"len now:\", len(queue))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>len: 2 cap: 3\nAsha\nRavi\nlen now: 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A buffered channel works like a small queue. You put two names in, so <code>len<\/code> is 2 while <code>cap<\/code> stays 3. Then you take them out in the same order they went in.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Wait for a Goroutine to Finish<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ cookFood does some work and then sends true to say it has finished.\nfunc cookFood(done chan bool) {\n    fmt.Println(\"cooking rice...\")\n    fmt.Println(\"rice is ready\")\n    done &lt;- true \/\/ tell main that the work is finished\n}\n\nfunc main() {\n    done := make(chan bool) \/\/ a channel that carries true or false\n\n    go cookFood(done) \/\/ start the work in a new goroutine\n\n    &lt;-done \/\/ wait here; we do not need the value itself\n    fmt.Println(\"dinner is served\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cooking rice...\nrice is ready\ndinner is served<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is the simplest way to wait for a goroutine. <code>main<\/code> starts <code>cookFood<\/code> and then blocks on <code>&lt;-done<\/code>. When the goroutine sends <code>true<\/code>, <code>main<\/code> wakes up and prints the last line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Range over a Channel and Close<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    squares := make(chan int)\n\n    go func() {\n        for i := 1; i &lt;= 5; i++ {\n            squares &lt;- i * i \/\/ send the square of i\n        }\n        close(squares) \/\/ close means: no more values are coming\n    }()\n\n    \/\/ range keeps receiving until the channel is closed and empty.\n    for square := range squares {\n        fmt.Print(square, \" \")\n    }\n    fmt.Println(\"| done\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 4 9 16 25 | done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The goroutine sends five squares and then closes the channel. The <code>range<\/code> loop in <code>main<\/code> prints each value as it arrives. Without <code>close<\/code>, the loop would wait forever after the last value, and Go would report a deadlock.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Detect a Closed Channel with ok<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := make(chan int, 2)\n    numbers &lt;- 10\n    close(numbers)\n\n    \/\/ ok is true when a real value was received.\n    value, ok := &lt;-numbers \/\/ the buffered 10 is still there\n    fmt.Println(value, ok)\n\n    value, ok = &lt;-numbers \/\/ the channel is closed and empty now\n    fmt.Println(value, ok)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>10 true\n0 false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After close, a receiver still gets any values left in the buffer. So the first receive gets 10 and <code>ok<\/code> is true. Once the channel is empty, you get the zero value 0 and <code>ok<\/code> is false.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Patterns in Go Channel Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go channel programs show the patterns you will use in real projects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Producer and Consumer<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n)\n\n\/\/ producer sends order IDs. chan&lt;- int means it may only send.\nfunc producer(orders chan&lt;- int, count int) {\n    for id := 1; id &lt;= count; id++ {\n        orders &lt;- id\n    }\n    close(orders) \/\/ the producer owns the channel, so it closes it\n}\n\n\/\/ consumer receives orders. &lt;-chan int means it may only receive.\n\/\/ wg is a wait group: it lets main wait until this goroutine is done.\nfunc consumer(orders &lt;-chan int, wg *sync.WaitGroup) {\n    defer wg.Done() \/\/ defer runs wg.Done() when this function returns\n    for id := range orders {\n        fmt.Println(\"shipping order\", id)\n    }\n}\n\nfunc main() {\n    orders := make(chan int, 2)\n    var wg sync.WaitGroup\n    wg.Add(1)               \/\/ we will wait for one goroutine\n    go consumer(orders, &amp;wg) \/\/ &amp;wg passes a pointer, so both share one wait group\n    producer(orders, 4)\n    wg.Wait() \/\/ wait until the consumer has handled every order\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>shipping order 1\nshipping order 2\nshipping order 3\nshipping order 4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The producer sends four order IDs and closes the channel. The consumer ranges over the same channel and prints each order. Then <code>wg.Wait()<\/code> keeps <code>main<\/code> alive until the consumer calls <code>wg.Done()<\/code>. The arrows in <code>chan&lt;- int<\/code> and <code>&lt;-chan int<\/code> also stop each side from doing the wrong job by mistake.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Add Up Numbers and Send Back the Total<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ sumNumbers adds every number and sends the total into the result channel.\nfunc sumNumbers(numbers []int, result chan int) {\n    total := 0\n    for _, number := range numbers { \/\/ _ skips the index we do not need\n        total += number\n    }\n    result &lt;- total \/\/ send the answer back to main\n}\n\nfunc main() {\n    prices := []int{120, 80, 50}\n    result := make(chan int)\n\n    go sumNumbers(prices, result) \/\/ do the work in a goroutine\n\n    total := &lt;-result \/\/ wait for the answer\n    fmt.Println(\"bill total:\", total)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>bill total: 250<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is how a goroutine returns a value. A goroutine cannot use <code>return<\/code> to give <code>main<\/code> a result. Instead, it sends the result into a channel, and <code>main<\/code> receives it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: A Generator Function<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ evens returns a receive-only channel that gives even numbers up to limit.\nfunc evens(limit int) &lt;-chan int {\n    output := make(chan int)\n    go func() {\n        defer close(output) \/\/ close the channel when the loop ends\n        for number := 0; number &lt;= limit; number += 2 {\n            output &lt;- number\n        }\n    }()\n    return output \/\/ return at once; the goroutine keeps sending\n}\n\nfunc main() {\n    for number := range evens(10) {\n        fmt.Print(number, \" \")\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0 2 4 6 8 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>evens<\/code> function starts a goroutine and returns the channel right away. Then the caller just ranges over it, without knowing a goroutine exists. When the loop inside ends, <code>defer<\/code> closes the channel and the <code>range<\/code> in <code>main<\/code> stops.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: A Pipeline of Stages<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ generate sends each given number into a new channel.\n\/\/ numbers ...int means the function accepts any count of ints.\nfunc generate(numbers ...int) &lt;-chan int {\n    output := make(chan int)\n    go func() {\n        for _, number := range numbers {\n            output &lt;- number\n        }\n        close(output)\n    }()\n    return output\n}\n\n\/\/ square reads numbers from input and sends their squares on.\nfunc square(input &lt;-chan int) &lt;-chan int {\n    output := make(chan int)\n    go func() {\n        for number := range input { \/\/ read from the previous stage\n            output &lt;- number * number \/\/ send to the next stage\n        }\n        close(output)\n    }()\n    return output\n}\n\nfunc main() {\n    \/\/ Step 1: generate 1, 2, 3.\n    \/\/ Step 2: square them once (1, 4, 9).\n    \/\/ Step 3: square them again (1, 16, 81).\n    for value := range square(square(generate(1, 2, 3))) {\n        fmt.Print(value, \" \")\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 16 81<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each stage is a goroutine, and channels connect the stages. Values flow through like parts on an assembly line. When one stage closes its output, the next stage&#8217;s <code>range<\/code> ends, so the close travels down the line. See our <a href=\"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/\">Go pipeline pattern guide<\/a> for fan-out and fan-in.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">select in Go Channel Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Go channel programs, <code>select<\/code> waits on several channel operations and runs the first one that is ready.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Timeout with select and time.After<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\n\/\/ slowAPI pretends to call a server that answers after the given delay.\nfunc slowAPI(delay time.Duration) &lt;-chan string {\n    reply := make(chan string, 1) \/\/ buffered so the goroutine never gets stuck\n    go func() {\n        time.Sleep(delay)\n        reply &lt;- \"response\"\n    }()\n    return reply\n}\n\nfunc main() {\n    delays := []time.Duration{50 * time.Millisecond, 300 * time.Millisecond}\n    for _, delay := range delays {\n        \/\/ select waits for whichever case is ready first.\n        select {\n        case answer := &lt;-slowAPI(delay):\n            fmt.Println(delay, \"-&gt;\", answer)\n        case &lt;-time.After(100 * time.Millisecond): \/\/ give up after 100ms\n            fmt.Println(delay, \"-&gt; timeout\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>50ms -&gt; response\n300ms -&gt; timeout<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Whichever channel is ready first wins. The 50ms call answers before the 100ms timer, so you see the response. But the 300ms call is too slow, so the timer wins. A buffer of 1 lets the slow goroutine finish its send later, even though nobody reads it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Non-Blocking Send with default<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    alerts := make(chan string, 1) \/\/ room for only one alert\n    for _, alert := range []string{\"CPU high\", \"disk full\", \"memory low\"} {\n        select {\n        case alerts &lt;- alert: \/\/ works only if there is room\n            fmt.Println(\"queued:\", alert)\n        default: \/\/ runs when the send would block\n            fmt.Println(\"dropped:\", alert)\n        }\n    }\n    fmt.Println(\"in queue:\", &lt;-alerts)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>queued: CPU high\ndropped: disk full\ndropped: memory low\nin queue: CPU high<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first alert fills the only slot. After that, a send would block, so <code>select<\/code> runs <code>default<\/code> and drops the alert. This is useful when you would rather drop a message than slow the sender down.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Stop a Goroutine with a done Channel<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    done := make(chan struct{}) \/\/ struct{} carries no data; it is just a signal\n    ticks := make(chan int)\n\n    go func() {\n        defer close(ticks)\n        for i := 1; ; i++ { \/\/ no end condition: loop until told to stop\n            select {\n            case &lt;-done: \/\/ a closed channel is always ready to receive\n                return\n            case ticks &lt;- i:\n                time.Sleep(10 * time.Millisecond)\n            }\n        }\n    }()\n\n    for tick := range ticks {\n        fmt.Println(\"tick\", tick)\n        if tick == 3 {\n            close(done) \/\/ ask the goroutine to stop\n            break\n        }\n    }\n    fmt.Println(\"stopped\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>tick 1\ntick 2\ntick 3\nstopped<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The goroutine keeps sending ticks until <code>done<\/code> is closed. After tick 3, <code>main<\/code> closes <code>done<\/code> and leaves the loop. Closing <code>done<\/code> wakes every goroutine waiting on it. In real apps, <code>context.Context<\/code> does the same job, as in our <a href=\"https:\/\/smitabharat.com\/blog\/go-context-beginners-guide\/\">Go context guide<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Go Channel Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These two Go channel programs are asked in almost every concurrency round.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Ping-Pong Between Two Goroutines<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n)\n\n\/\/ player waits for the ball, hits it, and sends it back with a higher number.\nfunc player(name string, receive &lt;-chan int, send chan&lt;- int, wg *sync.WaitGroup) {\n    defer wg.Done()\n    for ball := range receive { \/\/ wait for the ball\n        fmt.Println(name, \"hits\", ball)\n        if ball == 6 {\n            close(send) \/\/ game over: this ends the other player's loop\n            return\n        }\n        send &lt;- ball + 1 \/\/ send it back\n    }\n    close(send) \/\/ the other side closed, so close ours too\n}\n\nfunc main() {\n    ping := make(chan int)\n    pong := make(chan int)\n    var wg sync.WaitGroup\n    wg.Add(2) \/\/ wait for two players\n    go player(\"ping\", ping, pong, &amp;wg)\n    go player(\"pong\", pong, ping, &amp;wg)\n    ping &lt;- 1 \/\/ serve the first ball\n    wg.Wait()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>ping hits 1\npong hits 2\nping hits 3\npong hits 4\nping hits 5\npong hits 6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The ball passes back and forth on two unbuffered channels, so the order is always the same. Each player reads from one channel and sends on the other. When the ball reaches 6, one player closes its channel, which ends the other player&#8217;s loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Merge Two Channels (Fan-In)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"slices\"\n    \"sync\"\n)\n\n\/\/ copyInto moves every value from source into output.\nfunc copyInto(source &lt;-chan string, output chan&lt;- string, wg *sync.WaitGroup) {\n    defer wg.Done()\n    for value := range source {\n        output &lt;- value\n    }\n}\n\n\/\/ closeWhenDone waits for both copiers and then closes output.\nfunc closeWhenDone(output chan string, wg *sync.WaitGroup) {\n    wg.Wait()\n    close(output)\n}\n\n\/\/ merge joins two channels into one.\nfunc merge(first, second &lt;-chan string) &lt;-chan string {\n    output := make(chan string)\n    var wg sync.WaitGroup\n    wg.Add(2)\n    go copyInto(first, output, &amp;wg)\n    go copyInto(second, output, &amp;wg)\n    go closeWhenDone(output, &amp;wg) \/\/ close only when both are done\n    return output\n}\n\n\/\/ feed sends the given cities into a new channel.\nfunc feed(cities ...string) &lt;-chan string {\n    output := make(chan string)\n    go func() {\n        for _, city := range cities {\n            output &lt;- city\n        }\n        close(output)\n    }()\n    return output\n}\n\nfunc main() {\n    var allCities []string\n    for city := range merge(feed(\"pune\", \"goa\"), feed(\"delhi\")) {\n        allCities = append(allCities, city) \/\/ append adds to the slice\n    }\n    slices.Sort(allCities) \/\/ arrival order varies, so sort for stable output\n    fmt.Println(allCities)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[delhi goa pune]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Two goroutines copy values from each input into one shared output channel. A third goroutine waits for both copiers and then closes the output. Because the arrival order can change from run to run, you sort the result before printing it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Buffered vs Unbuffered Go Channel Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every one of these Go channel programs picks a channel kind. The diagram and table below compare the two.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-1024x640.png\" alt=\"Go channel programs comparison of unbuffered and buffered channels\" class=\"wp-image-825\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">An unbuffered channel makes sender and receiver meet, while a buffered channel lets the sender continue until the buffer is full.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Unbuffered make(chan T)<\/th><th>Buffered make(chan T, n)<\/th><\/tr><\/thead><tbody><tr><td>Send blocks<\/td><td>Until a receiver takes it<\/td><td>Only when the buffer is full<\/td><\/tr><tr><td>Sync guarantee<\/td><td>Sender knows it was received<\/td><td>Sender only knows it was queued<\/td><\/tr><tr><td>Use in a single goroutine<\/td><td>Deadlocks<\/td><td>Works up to n values<\/td><\/tr><tr><td>Typical use<\/td><td>Hand-off, turns, signals<\/td><td>Queues, smoothing bursts<\/td><\/tr><tr><td>Memory<\/td><td>No storage<\/td><td>Space for n values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use unbuffered channels when timing matters, and buffered channels when you want a small queue between fast and slow parts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Channel Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sending with no receiver:<\/strong> an unbuffered send in <code>main<\/code> alone deadlocks.<\/li>\n\n\n<li><strong>Forgetting to close:<\/strong> a <code>range<\/code> loop never ends, and Go reports a deadlock.<\/li>\n\n\n<li><strong>Closing from the receiver:<\/strong> only the sender should close, or it may panic with &#8220;send on closed channel&#8221;.<\/li>\n\n\n<li><strong>Closing twice:<\/strong> this panics, so make one goroutine responsible for closing.<\/li>\n\n\n<li><strong>Leaking goroutines on timeout:<\/strong> give the result channel a buffer of 1 so the late sender does not block forever.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Channel Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use directional types<\/strong> like <code>&lt;-chan T<\/code> in function signatures.<\/li>\n\n\n<li><strong>Let the producer close<\/strong>, and let consumers use <code>range<\/code>.<\/li>\n\n\n<li><strong>Use struct{} for signals<\/strong>, such as <code>done chan struct{}<\/code>, because it carries no data.<\/li>\n\n\n<li><strong>Add timeouts with select<\/strong> whenever you wait on something outside your control.<\/li>\n\n\n<li><strong>Prefer context.Context<\/strong> for cancellation in real services.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Channel Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers ask these Go channel programs more than any other concurrency questions. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Closed Channel Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What happens when you send on a closed channel?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nfunc main() {\n    numbers := make(chan int, 1)\n    close(numbers)\n    numbers &lt;- 1 \/\/ sending on a closed channel panics\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>panic: send on closed channel<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go stops the program with a panic. Once a channel is closed, nobody may send on it again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. Can you close a channel twice?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nfunc main() {\n    numbers := make(chan int)\n    close(numbers)\n    close(numbers) \/\/ the second close panics\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>panic: close of closed channel<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No, the second <code>close<\/code> panics. That is why only one goroutine should be in charge of closing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    words := make(chan string)\n    close(words)\n\n    word, ok := &lt;-words\n    fmt.Printf(\"%q %v\\n\", word, ok) \/\/ %q prints the string with quotes\n    fmt.Printf(\"%q\\n\", &lt;-words)     \/\/ still returns the zero value\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\"\" false\n\"\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Receiving from a closed channel never blocks. It returns the zero value right away, every time. For a string, the zero value is the empty string <code>\"\"<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Blocking and Deadlock Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := make(chan int, 2)\n    numbers &lt;- 1\n    numbers &lt;- 2\n    numbers &lt;- 3 \/\/ buffer is full and nobody is receiving\n    fmt.Println(&lt;-numbers)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>fatal error: all goroutines are asleep - deadlock!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The buffer holds two values. The third send blocks, and since no other goroutine exists, Go reports a deadlock.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What happens when you use a nil channel?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sending to or receiving from a nil channel blocks forever. In a <code>select<\/code>, a nil channel case is simply never chosen, which is a handy way to turn a case off.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := make(chan int, 3)\n    for i := range 3 { \/\/ range 3 gives i = 0, 1, 2\n        numbers &lt;- i\n    }\n    close(numbers)\n\n    sum := 0\n    for number := range numbers {\n        sum += number\n    }\n    fmt.Println(sum, len(numbers), cap(numbers))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 0 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop drains 0 + 1 + 2, which is 3. After that, the channel is empty, so <code>len<\/code> is 0, but <code>cap<\/code> stays 3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">select Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    channelA := make(chan string, 1)\n    channelB := make(chan string, 1)\n    channelB &lt;- \"from b\" \/\/ only channelB has a value\n\n    select {\n    case message := &lt;-channelA:\n        fmt.Println(message)\n    case message := &lt;-channelB:\n        fmt.Println(message)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>from b<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only <code>channelB<\/code> has a value, so only that case is ready. If both were ready, Go would pick one at random.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What does an empty select{} do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It blocks forever. It is sometimes used at the end of <code>main<\/code> in small demo servers, but in real code, waiting on a signal or a context is better.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you run code on a schedule?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ A ticker sends on its channel ticker.C every 20 milliseconds.\n    ticker := time.NewTicker(20 * time.Millisecond)\n    defer ticker.Stop() \/\/ always stop tickers to free resources\n\n    for i := 1; i &lt;= 3; i++ {\n        &lt;-ticker.C \/\/ wait for the next tick\n        fmt.Println(\"heartbeat\", i)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>heartbeat 1\nheartbeat 2\nheartbeat 3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>time.Ticker<\/code> sends on its channel <code>C<\/code> at a fixed interval. Each loop waits for one tick and then prints a line. It is used for heartbeats, polling and periodic cleanup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Design Questions on Go Channel Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. Who should close a channel?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The sender, and only one of them. Receivers cannot know if more values are coming, and closing from the wrong side causes &#8220;send on closed channel&#8221; panics. With many senders, close after a <code>WaitGroup<\/code> says they are all done, as in Program 14.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. Channels or mutexes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use channels to pass ownership of data or to signal events between goroutines. Use a mutex to protect a shared value, such as a counter or a cache. Both are correct tools; pick the one that makes the code clearer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. Do you have to close every channel?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Closing is only a signal for receivers that use <code>range<\/code> or need to know the stream has ended. A channel nobody waits on will be garbage collected when nothing refers to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pipelines are a favourite among Go channel programs. Build one with three stages: the first sends numbers 1 to 20, the second keeps only multiples of 3, and the third adds them up and prints the total. Hint: copy the <code>generate<\/code> and <code>square<\/code> pattern from Program 9, and make the middle stage a filter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/tour\/concurrency\/2\">A Tour of Go: Channels<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/pipelines\">Go concurrency patterns: pipelines (Go blog)<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Channel_types\">Go spec: channel types<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go channel programs pass values between goroutines with <code>ch &lt;- v<\/code> and <code>&lt;-ch<\/code>.<\/li>\n\n\n<li>Unbuffered channels make both sides meet, while buffered channels queue up to n values.<\/li>\n\n\n<li>Close a channel from the sender side, and receive with <code>range<\/code> or <code>v, ok<\/code>.<\/li>\n\n\n<li><code>select<\/code> waits on many channels, and <code>time.After<\/code> adds timeouts.<\/li>\n\n\n<li>Sending on or closing a closed channel panics, and a lone blocked send deadlocks.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we protect shared data and control how many goroutines work at once. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-mutex-worker-pool-programs\/\">Go mutex and worker pool programs<\/a>, with safe counters, worker pools and context cancel. For interview practice, see the <a href=\"https:\/\/smitabharat.com\/blog\/go-channels-interview-questions-part-15\/\">Go channels interview questions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go channel programs let goroutines send values to each other safely, without shared variables or locks. Go&#8217;s motto is &#8220;do not communicate by sharing&hellip;<\/p>\n","protected":false},"author":1,"featured_media":823,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,37,95,11,104],"swapz_series":[],"class_list":["post-826","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-channels","tag-go-interview-questions","tag-go-lang","tag-go-programs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Channel Programs: Buffered, select, Pipelines<\/title>\n<meta name=\"description\" content=\"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-channel-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Channel Programs: Buffered, select, Pipelines\" \/>\n<meta property=\"og:description\" content=\"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-channel-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-09T05:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Channel Programs with Output: Buffered, select and Pipelines\",\"datePublished\":\"2026-10-09T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/\"},\"wordCount\":2013,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-channel-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Channels\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/\",\"name\":\"Go Channel Programs: Buffered, select, Pipelines\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-channel-programs-featured.png\",\"datePublished\":\"2026-10-09T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:29+00:00\",\"description\":\"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-channel-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-channel-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Channel Programs featured image: channel, select and pipeline output\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-channel-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Channel Programs with Output: Buffered, select and Pipelines\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Channel Programs: Buffered, select, Pipelines","description":"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Channel Programs: Buffered, select, Pipelines","og_description":"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&A.","og_url":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-09T05:30:00+00:00","article_modified_time":"2026-11-28T19:59:29+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Channel Programs with Output: Buffered, select and Pipelines","datePublished":"2026-10-09T05:30:00+00:00","dateModified":"2026-11-28T19:59:29+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/"},"wordCount":2013,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png","keywords":["Beginner","Go Channels","Go Interview Questions","Go Lang","Go Programs"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/","name":"Go Channel Programs: Buffered, select, Pipelines","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png","datePublished":"2026-10-09T05:30:00+00:00","dateModified":"2026-11-28T19:59:29+00:00","description":"Go channel programs with output: unbuffered and buffered channels, range and close, select with timeout, tickers and pipelines, plus interview Q&A.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-channel-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-channel-programs-featured.png","width":2400,"height":1260,"caption":"Go Channel Programs featured image: channel, select and pipeline output"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-channel-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Channel Programs with Output: Buffered, select and Pipelines"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=826"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/826\/revisions"}],"predecessor-version":[{"id":895,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/826\/revisions\/895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/823"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=826"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}