# Review my pipeline pattern in go (new to the language)

**URL:** <https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942>\
**Category:** Code Review\
**Created:** [May 20, 2026, 6:18pm UTC](https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942 "2026-05-20T18:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DayDreamer](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@DayDreamer](https://forum.golangbridge.org/u/DayDreamer)\
**Post date:** [May 20, 2026, 6:18pm UTC](https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942/1 "2026-05-20T18:18:02Z")

</div>

Hello Everyone,

I am new to go language and learning the concurrency in go and one of the common patterns is “pipeline“. Below is my take on the pattern, please feel free to review it and let me know what all I can improve

```go
package main

import (
"context"
"fmt"
"runtime"
"sync"
"time"
)

func producer(ctx context.Context, jobsCh chan<- int) {
    defer close(jobsCh)
    i := 0
    for {
        select {
        case jobsCh ← i:
            i++
            time.Sleep(50 * time.Millisecond)
        case <-ctx.Done():
            fmt.Println("Stopping producer gorutine and jobsCh channel gracefully.")
            return
        }
    }
}

func worker(jobsCh <-chan int, resultCh chan<- int, wg *sync.WaitGroup) {
    defer wg.Done()
    for i := range jobsCh {
        resultCh ← i * i
    }
}

func result(resultCh <-chan int) {
    for s := range resultCh {
        fmt.Printf("square %d\n", s)
    }
}

func coordinator(wg *sync.WaitGroup, resultCh chan<- int){
    wg.Wait()
    close(resultCh)
    fmt.Println("Stopping coordinator/worker gorutines and resultCh channel gracefully.")
}

func main() {
    ctx, cancel := context.WithTimeout(
        context.Background(),
        1500*time.Millisecond
    )
    defer cancel()

    jobsCh := make(chan int, 1024)
    resultCh := make(chan int, 1024)

    go producer(ctx, jobsCh)

    var wg sync.WaitGroup
    for range 3 {
	    wg.Add(1)
	    go worker(jobsCh, resultCh, &wg)
    }

    go coordinator(&wg, resultCh)

    result(resultCh)

    fmt.Printf("Pipeline fully drained !\n")
    fmt.Printf("Number of gorutines : %d\n", runtime.NumGoroutine()) // should be 1
}

```

Also, could you let me know other common and important concurrency patterns like pubsub etc.

Cheers,  
DD

---

<div class="post-metadata">

**Author:** ![johandalabacka](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/johandalabacka/32/4477_2.png) [@johandalabacka](https://forum.golangbridge.org/u/johandalabacka)\
**Post date:** [May 25, 2026, 12:18am UTC](https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942/2 "2026-05-25T00:18:41Z")

</div>

> [@DayDreamer](#):
>
> ```auto
> wg.Add(1)
> go worker(jobsCh, resultCh, &wg)
> 
> ```

On small change would be to use the newer construct `wg.Run` as seen here: [Go by Example: WaitGroups](https://gobyexample.com/waitgroups) then you don’t need `wg.Add` and `wg.Done`  
Buy this isn’t really an answer to your query…

---

<div class="post-metadata">

**Author:** ![Yamil\_Bracho](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/yamil_bracho/32/5141_2.png) [@Yamil\_Bracho](https://forum.golangbridge.org/u/Yamil_Bracho)\
**Post date:** [May 25, 2026, 3:56pm UTC](https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942/3 "2026-05-25T15:56:11Z")

</div>

I think you can check others pipeline implementations in Go and the concept behind that pattern. That way you can understand best the problem and then make the needed changes to your code…

Just my two cents…

---

<div class="post-metadata">

**Author:** ![mdmci](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/m/b77776/32.png) [@mdmci](https://forum.golangbridge.org/u/mdmci)\
**Post date:** [May 25, 2026, 10:18pm UTC](https://forum.golangbridge.org/t/review-my-pipeline-pattern-in-go-new-to-the-language/41942/4 "2026-05-25T22:18:35Z")

</div>

If by “pipeline” you mean something like a Linux shell pipeline, this isn’t it. A wonderful thing about such pipelines is that they hide the synchronization method. So I am puzzled about the presence of Sync code.
