Skip to content

Expose Future.wait() and Future.err as part of public API #86

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

Closed
bm0 opened this issue Dec 5, 2019 · 3 comments
Closed

Expose Future.wait() and Future.err as part of public API #86

bm0 opened this issue Dec 5, 2019 · 3 comments

Comments

@bm0
Copy link

bm0 commented Dec 5, 2019

Hi guys!
We try implement replicaset using this connector.
Replicaset in our understanding is thing that collect multiple connections and can do retry query when one of connection timed out or unavailable.

There is a problem. We make *Async() queries in loop over connection, after we can't understand whether to retry because for this we need to do two things:

  1. Wait for Future will filled.
  2. Check that Future.err equals nil. If it is not, try again on next connection.
for i, conn := range connections {
	futCh := make(chan *tarantool.Future, 1)
	errCh := make(chan error, 1)
	ctx, cancel := context.WithTimeout(context.Background(), queryTimeout)

	go func() {
		fut := query(conn)
		fut.wait()
		if fut.err != nil {
			errCh <- fut.err
			return
		}
		
                futCh <- fut
	}()

	select {
	case <-ctx.Done():
		cancel()
		continue
	case fut := <-futCh:
		cancel()
		return fut, nil
	case err := <-errCh:
		cancel()
		return nil, err
		}
	}
}
@bm0
Copy link
Author

bm0 commented Dec 5, 2019

I would like to discuss with you the possibility of adding such functionality and its design. I will be glad to contribute to your project.

@funny-falcon
Copy link

Probably I read it wrong, but I don't understand at the moment, why Future.Get() doesn't satisfy you.

@funny-falcon
Copy link

I pushed commit that exposes WaitChan() and Err().

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

No branches or pull requests

2 participants