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

how to call recv with timeout on SUB socket? #37

Open
lunfardo314 opened this issue Dec 8, 2018 · 1 comment
Open

how to call recv with timeout on SUB socket? #37

lunfardo314 opened this issue Dec 8, 2018 · 1 comment

Comments

@lunfardo314
Copy link

lunfardo314 commented Dec 8, 2018

optional context for recv? Or use WithTimeout in

zmq4/socket.go

Line 121 in 91805d6

func (sck *socket) Recv() (Msg, error) {
?

@sbinet
Copy link
Contributor

sbinet commented Jan 7, 2019

yeah, right now, this is only possible like so:

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
ch := make(chan error)
go func() {
    msg, err = sck.Recv()
    ch <- err
}()
select {
case <-ctx.Done():
case err := <- ch:
    // ...
}

I guess one could indeed wire in a ctx context.Context argument to the Socket.Recv and Socket.Send methods...

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