Skip to content

Instantly share code, notes, and snippets.

@andrzejkrzywda
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrzejkrzywda/063f2cb42e9142ff6e19 to your computer and use it in GitHub Desktop.
Save andrzejkrzywda/063f2cb42e9142ff6e19 to your computer and use it in GitHub Desktop.
# CUSTOM EXCEPTIONS
class CallAlreadyInProgress < StandardError
end
class Dialer
def call(number)
raise CallAlreadyInProgress.new if call_already_in_progress?
end
end
dialer = Dialer.new
begin
dialer.call(number)
rescue CallAlreadyInProgress
ui_notifier.send_message("Call already in progress")
end
# with domain events
class CallAlreadyInProgress < Event
end
class ConnectionEstablished < Event
end
class Dialer
def call(number)
if call_already_in_progress?
CallAlreadyInProgress.new.publish()
return
end
ConnectionEstablished.new.publish()
end
end
# those two can be in different places of our project
event_bus.register(CallAlreadyInProgress, ui_notifier.send_message("Call already in progress"))
dialer.call(number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment