Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add .Response() and .Err() method for all subscriber #177

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

GoudanWoo
Copy link
Contributor

@GoudanWoo GoudanWoo commented Mar 21, 2024

Sometimes when we call this project to subscribe to some data, we need to use select {} for timeout control. like:

for {
select {
case <-ctx.Done():
return false, ctx.Err()
case <-time.After(*timeout):
return false, ErrTimeout
case resp, ok := <-sub.Response():
if !ok {
return false, fmt.Errorf("subscription closed")
}
if resp.Value.Err != nil {
// The transaction was confirmed, but it failed while executing (one of the instructions failed).
return true, fmt.Errorf("confirmed transaction with execution error: %v", resp.Value.Err)
} else {
// Success! Confirmed! And there was no error while executing the transaction.
return true, nil
}
case err := <-sub.Err():
return false, err
}
}

But if there is only .Recv() method, we are unable to complete requirements such as timeout control and active cancel. So I added .Response() and .Err() to do it.

@gagliardetto
Copy link
Owner

thanks!

@gagliardetto gagliardetto merged commit a8900f8 into gagliardetto:main Mar 22, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants