This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Artur Troian <[email protected]>
- Loading branch information
Showing
3 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |