@@ -20,8 +20,6 @@ import (
2020 "context"
2121 "fmt"
2222 "reflect"
23-
24- "fillmore-labs.com/promise/result"
2523)
2624
2725// AnyFuture matches a [Future] of any type.
@@ -31,36 +29,32 @@ type AnyFuture interface {
3129
3230// AwaitAll returns a function that yields the results of all futures.
3331// If the context is canceled, it returns an error for the remaining futures.
34- func AwaitAll [R any ](ctx context.Context , futures ... Future [R ]) func (yield func (int , result.Result [R ]) bool ) {
35- i := newIterator (ctx , convertValue [R ], futures )
36-
37- return i .yieldTo
32+ func AwaitAll [R any ](ctx context.Context , futures ... Future [R ]) func (yield func (int , Result [R ]) bool ) {
33+ return newIterator (ctx , convertValue [R ], futures )
3834}
3935
4036// AwaitAllAny returns a function that yields the results of all futures.
4137// If the context is canceled, it returns an error for the remaining futures.
42- func AwaitAllAny (ctx context.Context , futures ... AnyFuture ) func (yield func (int , result.Result [any ]) bool ) {
43- i := newIterator (ctx , convertValueAny , futures )
44-
45- return i .yieldTo
38+ func AwaitAllAny (ctx context.Context , futures ... AnyFuture ) func (yield func (int , Result [any ]) bool ) {
39+ return newIterator (ctx , convertValueAny , futures )
4640}
4741
4842// AwaitAllResults waits for all futures to complete and returns the results.
4943// If the context is canceled, it returns early with errors for the remaining futures.
50- func AwaitAllResults [R any ](ctx context.Context , futures ... Future [R ]) []result. Result [R ] {
44+ func AwaitAllResults [R any ](ctx context.Context , futures ... Future [R ]) []Result [R ] {
5145 return awaitAllResults (len (futures ), AwaitAll (ctx , futures ... ))
5246}
5347
5448// AwaitAllResultsAny waits for all futures to complete and returns the results.
5549// If the context is canceled, it returns early with errors for the remaining futures.
56- func AwaitAllResultsAny (ctx context.Context , futures ... AnyFuture ) []result. Result [any ] {
50+ func AwaitAllResultsAny (ctx context.Context , futures ... AnyFuture ) []Result [any ] {
5751 return awaitAllResults (len (futures ), AwaitAllAny (ctx , futures ... ))
5852}
5953
60- func awaitAllResults [R any ](n int , iter func (yield func (int , result. Result [R ]) bool )) []result. Result [R ] {
61- results := make ([]result. Result [R ], n )
54+ func awaitAllResults [R any ](n int , iter func (yield func (int , Result [R ]) bool )) []Result [R ] {
55+ results := make ([]Result [R ], n )
6256
63- iter (func (i int , r result. Result [R ]) bool {
57+ iter (func (i int , r Result [R ]) bool {
6458 results [i ] = r
6559
6660 return true
@@ -81,17 +75,17 @@ func AwaitAllValuesAny(ctx context.Context, futures ...AnyFuture) ([]any, error)
8175 return awaitAllValues (len (futures ), AwaitAllAny (ctx , futures ... ))
8276}
8377
84- func awaitAllValues [R any ](n int , iter func (yield func (int , result. Result [R ]) bool )) ([]R , error ) {
78+ func awaitAllValues [R any ](n int , iter func (yield func (int , Result [R ]) bool )) ([]R , error ) {
8579 results := make ([]R , n )
8680 var yieldErr error
8781
88- iter (func (i int , r result. Result [R ]) bool {
89- if r .Err () != nil {
90- yieldErr = fmt .Errorf ("list AwaitAllValues result %d: %w" , i , r .Err () )
82+ iter (func (i int , r Result [R ]) bool {
83+ if r .Err != nil {
84+ yieldErr = fmt .Errorf ("list AwaitAllValues result %d: %w" , i , r .Err )
9185
9286 return false
9387 }
94- results [i ] = r .Value ()
88+ results [i ] = r .Value
9589
9690 return true
9791 })
@@ -111,11 +105,11 @@ func AwaitFirstAny(ctx context.Context, futures ...AnyFuture) (any, error) {
111105 return awaitFirst (AwaitAllAny (ctx , futures ... ))
112106}
113107
114- func awaitFirst [R any ](iter func (yield func (int , result. Result [R ]) bool )) (R , error ) {
115- var v result. Result [R ]
108+ func awaitFirst [R any ](iter func (yield func (int , Result [R ]) bool )) (R , error ) {
109+ var v * Result [R ]
116110
117- iter (func (_ int , r result. Result [R ]) bool {
118- v = r
111+ iter (func (_ int , r Result [R ]) bool {
112+ v = & r
119113
120114 return false
121115 })
@@ -124,5 +118,5 @@ func awaitFirst[R any](iter func(yield func(int, result.Result[R]) bool)) (R, er
124118 return * new (R ), ErrNoResult
125119 }
126120
127- return v .V ()
121+ return v .Value , v . Err
128122}
0 commit comments