Created
July 31, 2017 19:50
-
-
Save davydovanton/1783af7cae254e4996fe62cbb6ba3b72 to your computer and use it in GitHub Desktop.
Hanami::Events
This file contains hidden or 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
require 'hanami/events' | |
events = Hanami::Events.build(:memory) | |
events.subscribe('user.created') { |payload| puts "Create user: #{payload}" } | |
events.subscribe('user.created') { |payload| puts "Send notification to user: #{payload}" } | |
events.subscribe('user.deleted') { |payload| puts "Delete user: #{payload}" } | |
events.broadcast('user.created', user_id: 1) | |
events.broadcast('user.deleted', user_id: 1) | |
# => Create user: {:user_id=>1} | |
# => Send notification to user: {:user_id=>1} | |
# => Delete user: {:user_id=>1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment