Skip to content

Question regarding graceful exit from poll #191

Open
@dandare100

Description

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):
		}

	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions