simplify
This commit is contained in:
parent
6f3654e147
commit
cd46986e57
|
@ -20,16 +20,18 @@ func (r *RequestContext[T]) String() string {
|
|||
return fmt.Sprintf("%+v", r.ans)
|
||||
}
|
||||
|
||||
func do[T any](r *RequestContext[T]) *RequestContext[T] {
|
||||
r.ans = *new(T)
|
||||
res, err := http.DefaultClient.Do(&r.req)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
func (r *RequestContext[T]) Do() func(r *RequestContext[T]) *RequestContext[T] {
|
||||
return func(r *RequestContext[T]) *RequestContext[T] {
|
||||
r.ans = *new(T)
|
||||
res, err := http.DefaultClient.Do(&r.req)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
return r
|
||||
}
|
||||
defer res.Body.Close()
|
||||
r.err = json.NewDecoder(res.Body).Decode(&r.ans)
|
||||
return r
|
||||
}
|
||||
defer res.Body.Close()
|
||||
r.err = json.NewDecoder(res.Body).Decode(&r.ans)
|
||||
return r
|
||||
}
|
||||
|
||||
type someResult struct {
|
||||
|
@ -45,7 +47,7 @@ func main() {
|
|||
req: *r,
|
||||
}
|
||||
}
|
||||
results := lambda.Filter(parallel.Map(requests, do[someResult], 4), func(r *RequestContext[someResult]) bool {
|
||||
results := lambda.Filter(parallel.Map(requests, requests[0].Do(), 4), func(r *RequestContext[someResult]) bool {
|
||||
return r.err == nil
|
||||
})
|
||||
for _, v := range results {
|
||||
|
|
Loading…
Reference in New Issue