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

Question regarding graceful exit from poll #191

Open
dandare100 opened this issue Nov 29, 2022 · 0 comments
Open

Question regarding graceful exit from poll #191

dandare100 opened this issue Nov 29, 2022 · 0 comments

Comments

@dandare100
Copy link

I would like to understand the best practice for gracefully exiting a poll loop when using this library (or zmq poll in general)

I have the following crude example, which works fine : Is there a more elegant way to do it ?

I realize there is only 1 socket in this example but more will be added.

Eish:
	for {

		sockets, _ := poller.Poll(time.Second * 3)

		for _, socket := range sockets {
			switch s := socket.Socket; s {
			case sub1:
				address, err := s.Recv(0)
				if err != nil {
					log.Errorf("Error receiving zmq message(1) : %v", err)
					continue
				}
				if msg, err := s.Recv(0); err != nil {
					log.Errorf("Error receiving zmq message(2) : %v", err)
					continue
				} else {
					mess := string(msg)
					fmt.Print("Received message from " + address + " channel.")
					fmt.Printf("%+v\n", mess)
				}
			}

		}

		select {
		case <-ctx.Done():
			log.Infof("Exiting zmq.")
			break Eish
		case <-time.After(time.Millisecond * 1):
		}

	}
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

1 participant