Skip to content

Commit

Permalink
feat: expose type Executor
Browse files Browse the repository at this point in the history
  • Loading branch information
RexSkz committed Nov 21, 2023
1 parent 302edaf commit 93067e2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// 1. define a list of functions
fns := []func() (interface{}, error){
fns := []gromise.Executor{
func() (interface{}, error) {
// business logic that may cause lots of time
return data, nil
Expand Down
4 changes: 3 additions & 1 deletion gromise.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func New(timeoutMs int) *Gromise {
// return nil
// }

func (g *Gromise) AllSettled(fns []func() (interface{}, error)) *AllSettledResult {
type Executor func() (interface{}, error)

func (g *Gromise) AllSettled(fns []Executor) *AllSettledResult {
result := newAllSettledResult()

go func() {
Expand Down
10 changes: 5 additions & 5 deletions gromise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestNewGromise(t *testing.T) {
fns := []func() (interface{}, error){
fns := []Executor{
func() (interface{}, error) {
time.Sleep(100 * time.Millisecond)
return 1, nil
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestNewGromise(t *testing.T) {
}

func TestError(t *testing.T) {
fns := []func() (interface{}, error){
fns := []Executor{
func() (interface{}, error) {
time.Sleep(100 * time.Millisecond)
return 1, nil
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestError(t *testing.T) {
}

func TestPanic(t *testing.T) {
fns := []func() (interface{}, error){
fns := []Executor{
func() (interface{}, error) {
time.Sleep(100 * time.Millisecond)
return 1, nil
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestPanic(t *testing.T) {
}

func TestTimeout(t *testing.T) {
fns := []func() (interface{}, error){
fns := []Executor{
func() (interface{}, error) {
time.Sleep(1000 * time.Millisecond)
return 1, nil
Expand All @@ -152,7 +152,7 @@ func TestTimeout(t *testing.T) {
}

func TestEmptyFns(t *testing.T) {
fns := []func() (interface{}, error){}
fns := []Executor{}
results, err := New(1000).AllSettled(fns).Await()

if err != nil {
Expand Down
Empty file modified scripts/run_tests.sh
100644 → 100755
Empty file.

0 comments on commit 93067e2

Please sign in to comment.