From d52bdb27c598bab837a48ecf544f16d413881a19 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 21 Sep 2020 12:49:33 +0300 Subject: [PATCH] [#33] util: Define worker pool interface Signed-off-by: Leonard Lyubich --- pkg/util/worker_pool.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pkg/util/worker_pool.go diff --git a/pkg/util/worker_pool.go b/pkg/util/worker_pool.go new file mode 100644 index 00000000..3083cf06 --- /dev/null +++ b/pkg/util/worker_pool.go @@ -0,0 +1,24 @@ +package util + +// WorkerPool represents the tool for control +// the execution of go-routine pool. +type WorkerPool interface { + // Submit queues a function for execution + // in a separate routine. + // + // Implementation must return any error encountered + // that prevented the function from being queued. + Submit(func()) error +} + +// SyncWorkerPool represents synchronous worker pool. +type SyncWorkerPool struct{} + +// Submit executes passed function immediately. +// +// Always returns nil. +func (SyncWorkerPool) Submit(fn func()) error { + fn() + + return nil +}