diff options
| author | sangtran <tranquangsang12.7@gmail.com> | 2026-09-03 23:10:33 +0700 |
|---|---|---|
| committer | sangtran <tranquangsang12.7@gmail.com> | 2026-09-03 23:10:33 +0700 |
| commit | 02123df8cc15896f97c1580e49d8e2a991e37ddd (patch) | |
| tree | d0c00bc3f65e5f5493a9dff8034c80640cb12960 /README | |
| signature | Verified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust | |
| download | quacker-main.tar.gz quacker-main.zip | |
Diffstat (limited to 'README')
| -rw-r--r-- | README | 125 |
1 files changed, 125 insertions, 0 deletions
| @@ -0,0 +1,125 @@ | |||
| 1 | QUACKER | ||
| 2 | ======= | ||
| 3 | |||
| 4 | Type-safe, composable concurrency patterns with backpressure for Go. | ||
| 5 | |||
| 6 | Quacker provides composable, channel-native concurrency primitives. | ||
| 7 | Backpressure propagates naturally through Go's channel semantics — | ||
| 8 | no custom protocols, no framework lock-in. | ||
| 9 | |||
| 10 | |||
| 11 | INSTALLATION | ||
| 12 | ------------ | ||
| 13 | |||
| 14 | go get git.sangtran.io.vn/quacker.git | ||
| 15 | |||
| 16 | Requirements: Go 1.25+ | ||
| 17 | |||
| 18 | |||
| 19 | PACKAGES | ||
| 20 | -------- | ||
| 21 | |||
| 22 | pipeline | ||
| 23 | Stream processing with backpressure. Compose stages into pipelines. | ||
| 24 | Each stage transforms a channel into a channel. | ||
| 25 | |||
| 26 | Example: | ||
| 27 | ctx, cancel := context.WithCancelCause(ctx) | ||
| 28 | |||
| 29 | out := pipeline.Run(ctx, input, | ||
| 30 | pipeline.Map(3, func(ctx context.Context, e Event) (Event, bool) { | ||
| 31 | enriched, err := enrich(ctx, e) | ||
| 32 | if err != nil { | ||
| 33 | cancel(err) | ||
| 34 | return e, false | ||
| 35 | } | ||
| 36 | return enriched, true | ||
| 37 | }), | ||
| 38 | pipeline.Filter(func(e Event) bool { return e.Priority > 0 }), | ||
| 39 | pipeline.Sink(5, func(ctx context.Context, e Event) { | ||
| 40 | store(ctx, e) | ||
| 41 | }), | ||
| 42 | ) | ||
| 43 | |||
| 44 | for range out {} | ||
| 45 | if err := context.Cause(ctx); err != nil { | ||
| 46 | log.Fatal(err) | ||
| 47 | } | ||
| 48 | |||
| 49 | Stages: Map, Filter, ForEach, Buffer, Tee, Take, Sink, Batch. | ||
| 50 | |||
| 51 | fanout | ||
| 52 | 1-to-N distribution. Distribute a single stream to multiple | ||
| 53 | consumers. RoundRobin for load balancing, Broadcast for pub/sub. | ||
| 54 | |||
| 55 | Example: | ||
| 56 | fo, _ := fanout.NewFanOut[int]( | ||
| 57 | fanout.WithWorkerCount(3), | ||
| 58 | fanout.WithStrategy(fanout.Broadcast), | ||
| 59 | ) | ||
| 60 | fo.Run(ctx, input) | ||
| 61 | |||
| 62 | for _, ch := range fo.Outputs() { | ||
| 63 | go consume(ch) | ||
| 64 | } | ||
| 65 | |||
| 66 | fanin | ||
| 67 | N-to-1 merge. Merge multiple channels into a single stream. | ||
| 68 | |||
| 69 | Example: | ||
| 70 | fi, _ := fanin.NewFanIn[int]() | ||
| 71 | fi.Add(stream1) | ||
| 72 | fi.Add(stream2) | ||
| 73 | fi.Add(stream3) | ||
| 74 | merged := fi.Run(ctx) | ||
| 75 | |||
| 76 | workerpool | ||
| 77 | Fixed-size worker pool with push-based task queuing, metrics, | ||
| 78 | and graceful shutdown. | ||
| 79 | |||
| 80 | Example: | ||
| 81 | pool, _ := workerpool.NewWorkerPool[MyTask](ctx, | ||
| 82 | workerpool.WithNumWorkers(4), | ||
| 83 | workerpool.WithTaskQueueSize(100), | ||
| 84 | ) | ||
| 85 | pool.Start() | ||
| 86 | pool.Push(task) | ||
| 87 | pool.StopAndWait() | ||
| 88 | |||
| 89 | |||
| 90 | HOW THEY COMPOSE | ||
| 91 | ---------------- | ||
| 92 | |||
| 93 | The primitives connect through channels — Go's universal connector: | ||
| 94 | |||
| 95 | +-- pipeline --+ | ||
| 96 | source --> fanout --+-- pipeline --+-- fanin --> pipeline --> sink | ||
| 97 | +-- pipeline --+ | ||
| 98 | |||
| 99 | Example: | ||
| 100 | fo.Run(ctx, source) | ||
| 101 | |||
| 102 | fast := pipeline.Run(ctx, fo.Outputs()[0], pipeline.Map(10, enrichFast)) | ||
| 103 | slow := pipeline.Run(ctx, fo.Outputs()[1], pipeline.Map(2, enrichSlow)) | ||
| 104 | |||
| 105 | fi.Add(fast) | ||
| 106 | fi.Add(slow) | ||
| 107 | merged := fi.Run(ctx) | ||
| 108 | |||
| 109 | out := pipeline.Run(ctx, merged, pipeline.Sink(5, store)) | ||
| 110 | |||
| 111 | |||
| 112 | DESIGN | ||
| 113 | ------ | ||
| 114 | |||
| 115 | - Backpressure is free. Channels block when full. No custom protocol. | ||
| 116 | - Errors use stdlib. context.WithCancelCause + context.Cause. | ||
| 117 | - Shutdown is clear. Close input for drain; cancel context for stop. | ||
| 118 | - Small interfaces. Observer interfaces are 2-3 methods, optional. | ||
| 119 | - Zero dependencies. Core logic is stdlib only (golang.org/x/sync). | ||
| 120 | |||
| 121 | |||
| 122 | LICENSE | ||
| 123 | ------- | ||
| 124 | |||
| 125 | MIT (see LICENSE) | ||
