Skip to content

Commit

Permalink
feat: port canonical runner
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Sep 30, 2024
1 parent d5ca789 commit 000b748
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions go/util/runner/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package runner

// Task is a function type which returns result instance
type Task func() Result

// Do executes task and send output to channel
func Do(task Task) <-chan Result {
ch := make(chan Result, 1)
go func() {
ch <- task()
}()
return ch
}

// Result interface wraps Value and Error methods.
type Result interface {
Value() interface{}
Error() error
}

// NewResult returns result instance with value as input
func NewResult(value interface{}, err error) Result {
return result{
value: value,
err: err,
}
}

type result struct {
value interface{}
err error
}

func (r result) Value() interface{} {
return r.value
}

func (r result) Error() error {
return r.err
}

0 comments on commit 000b748

Please sign in to comment.