-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from celluloid/publish-module-method
Publish module method, and pub/sub example.
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'celluloid/autostart' | ||
|
||
class Publisher | ||
include Celluloid | ||
include Celluloid::Notifications | ||
|
||
def initialize | ||
now = Time.now.to_f | ||
sleep now.ceil - now + 0.001 | ||
9.times { | ||
publish 'example_write_by_instance_method', Time.now | ||
} | ||
end | ||
end | ||
|
||
class Subscriber | ||
include Celluloid | ||
include Celluloid::Notifications | ||
include Celluloid::Logger | ||
|
||
def initialize | ||
info "Subscribing to topics." | ||
subscribe 'example_write_by_instance_method', :new_message | ||
subscribe 'example_write_by_class_method', :new_message | ||
end | ||
|
||
def new_message(topic,data) | ||
info "#{topic}: #{data}" | ||
end | ||
end | ||
|
||
sub = Subscriber.new | ||
|
||
Celluloid::Notifications.publish "example_write_by_class_method", Time.now | ||
|
||
pub = Publisher.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters