Skip to content

Commit

Permalink
fix: return directly if no futures
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi committed Aug 11, 2024
1 parent 02b95b4 commit b63afa0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func ToAny[T any](f *Future[T]) *Future[any] {
}

func AllOf[T any](fs ...*Future[T]) *Future[struct{}] {
if len(fs) == 0 {
return Done(struct{}{})
}

var done uint32
s := &state[struct{}]{}
c := int32(len(fs))
Expand Down
8 changes: 8 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ func TestAllOf(t *testing.T) {
}
}

func TestAllOfEmpty(t *testing.T) {
fs := make([]*Future[int], 0)
f := AllOf(fs...)
r, err := f.Get()
assert.Equal(t, struct{}{}, r)
assert.NoError(t, err)
}

func TestAllOfWhenErr(t *testing.T) {
target := rand.Intn(10)
vals := make([]int, 10)
Expand Down

0 comments on commit b63afa0

Please sign in to comment.