vardius / gollback

Go asynchronous simple function utilities, for managing execution of closures and callbacks
MIT License
123 stars 13 forks source link

Race returns the last error although other AsyncFunc succeeds #4

Closed pourplusquoi closed 1 year ago

pourplusquoi commented 1 year ago

Reproduce code:

import (
    "context"
    "errors"
    "fmt"
    "time"

    "github.com/vardius/gollback"
)

func main() {
    r, err := gollback.Race(
        context.Background(),
        func(ctx context.Context) (interface{}, error) {
            time.Sleep(time.Second)
            return 1, nil
        },
        func(ctx context.Context) (interface{}, error) {
            time.Sleep(time.Second)
            return 2, nil
        },
        func(ctx context.Context) (interface{}, error) {
            return nil, errors.New("failed")
        },
    )
    fmt.Println(r)
    fmt.Println(err)
}

It prints:

<nil>
failed

I would expect it to return 1 or 2. Am I missing something?

vardius commented 1 year ago

make sure to update to latest version, both package tests and example you provided do work for me correctly

1
<nil>

Process finished with the exit code 0

what is the go version you are using ? and please confirm if error still persists after you run

go get -u github.com/vardius/gollback && go mod tidy
pourplusquoi commented 1 year ago

Thanks for your reply, it can be reproduced on https://go.dev/play/p/ynNbtJ4q8VI. Probably because you didn't release the change.

vardius commented 1 year ago

good catch, I must have forgotten to do that https://github.com/vardius/gollback/releases/tag/v1.1.1

pourplusquoi commented 1 year ago

👍