-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Batcher runner implementation
Signed-off-by: Alexandros Filios <[email protected]>
- Loading branch information
1 parent
0278ab5
commit ed4a7c5
Showing
3 changed files
with
60 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package runner | ||
|
||
import "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/flogging" | ||
|
||
var logger = flogging.MustGetLogger("batch-executor") | ||
|
||
type BatchExecutor[I any, O any] interface { | ||
Execute(input I) (O, error) | ||
} | ||
|
||
type BatchRunner[V any] interface { | ||
Run(v V) error | ||
} | ||
|
||
type Output[O any] struct { | ||
Val O | ||
Err error | ||
} | ||
|
||
type ExecuteFunc[I any, O any] func([]I) []O |
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,32 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package runner | ||
|
||
func NewSerialRunner[V any](runner ExecuteFunc[V, error]) BatchRunner[V] { | ||
return &serialRunner[V]{executor: runner} | ||
} | ||
|
||
type serialRunner[V any] struct { | ||
executor ExecuteFunc[V, error] | ||
} | ||
|
||
func (r *serialRunner[V]) Run(val V) error { | ||
return r.executor([]V{val})[0] | ||
} | ||
|
||
func NewSerialExecutor[I any, O any](executor ExecuteFunc[I, Output[O]]) BatchExecutor[I, O] { | ||
return &serialExecutor[I, O]{executor: executor} | ||
} | ||
|
||
type serialExecutor[I any, O any] struct { | ||
executor ExecuteFunc[I, Output[O]] | ||
} | ||
|
||
func (r *serialExecutor[I, O]) Execute(input I) (O, error) { | ||
res := r.executor([]I{input})[0] | ||
return res.Val, res.Err | ||
} |