diff options
author | Valery Piashchynski <[email protected]> | 2020-12-22 23:27:51 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-22 23:27:51 +0300 |
commit | 1f6749ed4cf3cfd2beade4949945a382abd66b15 (patch) | |
tree | 7dff57a0223376746fd6cd49dc439f8766fe9f1b /pkg/pipe | |
parent | 95a72fe8003c66ac2d9a52b964aba4ee1d88363f (diff) |
Redisighn factory interface (add event listeners as variadic)v2.0.0-alpha28
Diffstat (limited to 'pkg/pipe')
-rwxr-xr-x | pkg/pipe/pipe_factory.go | 20 | ||||
-rwxr-xr-x | pkg/pipe/pipe_factory_test.go | 2 |
2 files changed, 8 insertions, 14 deletions
diff --git a/pkg/pipe/pipe_factory.go b/pkg/pipe/pipe_factory.go index f6211ab9..ecb3fa71 100755 --- a/pkg/pipe/pipe_factory.go +++ b/pkg/pipe/pipe_factory.go @@ -15,18 +15,12 @@ import ( // Factory connects to stack using standard // streams (STDIN, STDOUT pipes). -type Factory struct { - listener []events.EventListener -} +type Factory struct{} // NewPipeFactory returns new factory instance and starts // listening - -// todo: review tests -func NewPipeFactory(listeners ...events.EventListener) worker.Factory { - return &Factory{ - listener: listeners, - } +func NewPipeFactory() worker.Factory { + return &Factory{} } type SpawnResult struct { @@ -36,11 +30,11 @@ type SpawnResult struct { // SpawnWorker creates new Process and connects it to goridge relay, // method Wait() must be handled on level above. -func (f *Factory) SpawnWorkerWithTimeout(ctx context.Context, cmd *exec.Cmd) (worker.BaseProcess, error) { +func (f *Factory) SpawnWorkerWithTimeout(ctx context.Context, cmd *exec.Cmd, listeners ...events.EventListener) (worker.BaseProcess, error) { c := make(chan SpawnResult) const op = errors.Op("spawn worker with context") go func() { - w, err := workerImpl.InitBaseWorker(cmd, workerImpl.AddListeners(f.listener...)) + w, err := workerImpl.InitBaseWorker(cmd, workerImpl.AddListeners(listeners...)) if err != nil { c <- SpawnResult{ w: nil, @@ -119,9 +113,9 @@ func (f *Factory) SpawnWorkerWithTimeout(ctx context.Context, cmd *exec.Cmd) (wo } } -func (f *Factory) SpawnWorker(cmd *exec.Cmd) (worker.BaseProcess, error) { +func (f *Factory) SpawnWorker(cmd *exec.Cmd, listeners ...events.EventListener) (worker.BaseProcess, error) { const op = errors.Op("spawn worker") - w, err := workerImpl.InitBaseWorker(cmd, workerImpl.AddListeners(f.listener...)) + w, err := workerImpl.InitBaseWorker(cmd, workerImpl.AddListeners(listeners...)) if err != nil { return nil, errors.E(op, err) } diff --git a/pkg/pipe/pipe_factory_test.go b/pkg/pipe/pipe_factory_test.go index 3cef0646..dca09375 100755 --- a/pkg/pipe/pipe_factory_test.go +++ b/pkg/pipe/pipe_factory_test.go @@ -415,7 +415,7 @@ func Test_Broken(t *testing.T) { } } - w, err := NewPipeFactory(listener).SpawnWorkerWithTimeout(ctx, cmd) + w, err := NewPipeFactory().SpawnWorkerWithTimeout(ctx, cmd, listener) if err != nil { t.Fatal(err) } |