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

core.async example #105

Merged
merged 1 commit into from
Mar 10, 2014
Merged

core.async example #105

merged 1 commit into from
Mar 10, 2014

Conversation

stream-iori
Copy link
Member

I write a example about core.async in vert.x, i think this would be useful for someone.
hope you could checking my PR, if something doesn't correct.

tobias added a commit that referenced this pull request Mar 10, 2014
@tobias tobias merged commit b93a513 into vert-x:master Mar 10, 2014
@tobias
Copy link
Contributor

tobias commented Mar 10, 2014

Thanks for this! I cleaned it up a bit, and changed it to ping/pong 100 messages instead of 1: 02eaea3

The only things I changed in the logic from your original code was changing the alts! calls to <!, since we're only working with one channel in each case, and using (go-loop ...) instead of (go (loop ...)). go-loop is a convenience macro that puts a loop inside of a go.

Since it now sends 100 messages, the println's would interrupt each other, making the output unreadable. So I added a log function that uses a channel to serialize those printlns.

I've been copying the examples to a PR on https://github.com/vert-x/vertx-examples since we're about to be included as an official module. I'll copy this to that PR as well.

@stream-iori
Copy link
Member Author

Ha!

Thanks for your correction. :)

Toby Crawley writes:

Thanks for this! I cleaned it up a bit, and changed it to ping/pong 100 messages instead of 1: 02eaea3

The only things I changed in the logic from your original code was changing the alts! calls to <!, since we're only working with one channel in each case, and using (go-loop ...) instead of (go (loop ...)). go-loop is a convenience macro that puts a loop inside of a go.

Since it now sends 100 messages, the println's would interrupt each other, making the output unreadable. So I added a log function that uses a channel to serialize those printlns.

I've been copying the examples to a PR on https://github.com/vert-x/vertx-examples since we're about to be included as an official module. I'll copy this to that PR as well.


Reply to this email directly or view it on GitHub:
#105 (comment)

@dmarjenburgh
Copy link

A related question. core.async runs go blocks on a fixed size thread-pool. Since vert.x makes sure only one thread runs through each verticle, is it really a good idea to send messages over the eventbus inside of go-blocks? These would likely be send by a different thread than the verticle thread.

I suppose using put! and take! (with the default on-caller? arg to true) will ensure things get done on the verticle thread, but there is still a thread-pool inside of core.async in the background. Do you have any thoughts on this?

@stream-iori
Copy link
Member Author

These would likely be send by a different thread than the verticle thread.
I don't clear about this, i think send and reply always been invoked by Verticle Thread in Eventloop context.

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

Successfully merging this pull request may close these issues.

3 participants