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

Merge in Channels from vaughan0/go-zmq? #26

Open
schleppy opened this issue Oct 17, 2014 · 6 comments
Open

Merge in Channels from vaughan0/go-zmq? #26

schleppy opened this issue Oct 17, 2014 · 6 comments

Comments

@schleppy
Copy link

First off let me thank you for both writing, and maintaining this library.

I recently switched to it from github.com/vaughan0/go-zmq, mostly because there were some issues with that library I could not quite explain (like my inability to set a hwm despite doing everything I could think of including writing the cgo calls on every socket created for testing.)

The one thing I really miss is the abstraction given using Socket.Channels(). What I am doing, done the standard zmq way, would have me reading from a Router tcp socket, and sending work to a Dealer inproc, and having goroutines reading from that inproc, and then having the main process using a poller to read from the Dealer and write back out on the Router (I forget the name of this pattern at the moment.)

But the Channels abstraction is really nice. It creates a Pair in a single goroutine and uses go channels to communicate between the In and Out. Because so much of my code already relied on this paradigm, I spent some time and ported the channels.go file (https://github.com/vaughan0/go-zmq/blob/master/channels.go) to work with your library (mostly name changes for constants, and some type changes to match what you have done.)

I am wondering if you have any interest in adding this to zmq4? I could submit a pull request but wanted to make sure it was even something you would consider before going through with it.

Thanks again.

@driskell
Copy link

Looks pretty useful!

Does it not need thread locking, though?
http://golang.org/pkg/runtime/#LockOSThread

Otherwise between channel activities the routines may switch threads. ZeroMQ sockets are not thread safe.

@schleppy
Copy link
Author

That is an interesting point @driskell. That seems like an oversight by both the original author and myself.

@driskell
Copy link

Since the sockets never cross a Goroutine boundary (except after initial creation), I think it just needs each of those routines locking to an OS thread. Then it's probably good :)

I think even if this wasn't to be maintained and included - it could still be merged as an "example" pattern?

@schleppy
Copy link
Author

Yeah, it could be an example pattern. It just needs to be reworked to have Channels take the Socket as an arg vs being the receiver. I'll see if I have time today to try that.

@pebbe
Copy link
Owner

pebbe commented Oct 17, 2014

I am not an expert on design patters, so I have to rely on the judgement of contributers.Therefore I think the best place for design patterns is in the wiki: https://github.com/pebbe/zmq4/wiki/DesignPatterns

I will add a link in the documentation to the wiki

@darkdragon-001
Copy link

I created a PR to add a channel interface in #177 .

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

4 participants