Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active August 29, 2015 14:03
Show Gist options
  • Save tkfm-yamaguchi/62808d75f3ab366a44c0 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/62808d75f3ab366a44c0 to your computer and use it in GitHub Desktop.
wisper blocks publisher according to subscriber's process
require "wisper"
require "date"
class MyPublisher
include Wisper::Publisher
def tick(time)
publish(:tack, time)
end
end
if __FILE__ == $0
my_publisher = MyPublisher.new
my_publisher.on(:tack) do |time|
p time
sleep 1
end
5.times do
my_publisher.tick(Time.now)
sleep 1
end
end
=begin
Result:
$ bundle exec ruby main.rb
2014-07-08 08:27:14 +0900
2014-07-08 08:27:16 +0900
2014-07-08 08:27:18 +0900
2014-07-08 08:27:20 +0900
2014-07-08 08:27:22 +0900
MyListener blocks the subsequent processes ...
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment