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 /pipeline/options.go | |
| signature | Verified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust | |
| download | quacker-main.tar.gz quacker-main.zip | |
Diffstat (limited to 'pipeline/options.go')
| -rw-r--r-- | pipeline/options.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pipeline/options.go b/pipeline/options.go new file mode 100644 index 0000000..c8c616e --- /dev/null +++ b/pipeline/options.go | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | package pipeline | ||
| 2 | |||
| 3 | // StageObserver receives callbacks for stage lifecycle events. | ||
| 4 | type StageObserver interface { | ||
| 5 | OnItem() | ||
| 6 | OnDrop() | ||
| 7 | OnDone() | ||
| 8 | } | ||
| 9 | |||
| 10 | // StageOption configures a stage's behavior. | ||
| 11 | type StageOption func(*stageConfig) | ||
| 12 | |||
| 13 | type stageConfig struct { | ||
| 14 | observer StageObserver | ||
| 15 | bufferSize int | ||
| 16 | } | ||
| 17 | |||
| 18 | // WithObserver attaches an observer to a stage. | ||
| 19 | func WithObserver(obs StageObserver) StageOption { | ||
| 20 | return func(cfg *stageConfig) { cfg.observer = obs } | ||
| 21 | } | ||
| 22 | |||
| 23 | // WithBufferSize sets the output channel buffer size for a stage. | ||
| 24 | func WithBufferSize(size int) StageOption { | ||
| 25 | return func(cfg *stageConfig) { cfg.bufferSize = size } | ||
| 26 | } | ||
| 27 | |||
| 28 | func applyOpts(opts []StageOption) stageConfig { | ||
| 29 | var cfg stageConfig | ||
| 30 | for _, opt := range opts { | ||
| 31 | opt(&cfg) | ||
| 32 | } | ||
| 33 | return cfg | ||
| 34 | } | ||
