lib/ably/realtime/channel/channel_state_machine.rb in ably-0.7.2 vs lib/ably/realtime/channel/channel_state_machine.rb in ably-0.7.4

- old
+ new

@@ -33,35 +33,50 @@ after_transition(to: [:attaching]) do |channel| channel.manager.attach end before_transition(to: [:attached]) do |channel, current_transition| - channel.manager.sync current_transition.metadata + channel.manager.attached current_transition.metadata end after_transition(to: [:detaching]) do |channel, current_transition| channel.manager.detach current_transition.metadata end after_transition(to: [:detached]) do |channel, current_transition| - channel.manager.emit_error current_transition.metadata if current_transition.metadata + channel.manager.fail_messages_awaiting_ack nil_unless_error(current_transition.metadata) + channel.manager.emit_error current_transition.metadata if is_error_type?(current_transition.metadata) end after_transition(to: [:failed]) do |channel, current_transition| - channel.manager.emit_error current_transition.metadata + channel.manager.fail_messages_awaiting_ack nil_unless_error(current_transition.metadata) + channel.manager.emit_error current_transition.metadata if is_error_type?(current_transition.metadata) end # Transitions responsible for updating channel#error_reason - before_transition(to: [:attached, :detached, :failed]) do |channel, current_transition| - reason = current_transition.metadata if is_error_type?(current_transition.metadata) - channel.set_failed_channel_error_reason reason + before_transition(to: [:failed]) do |channel, current_transition| + channel.set_failed_channel_error_reason current_transition.metadata if is_error_type?(current_transition.metadata) end + before_transition(to: [:attached, :detached]) do |channel, current_transition| + if is_error_type?(current_transition.metadata) + channel.set_failed_channel_error_reason current_transition.metadata + else + # Attached & Detached are "healthy" final states so reset the error reason + channel.clear_error_reason + end + end + + def self.nil_unless_error(error_object) + error_object if is_error_type?(error_object) + end + private def channel object end + # Logged needs to be defined as it is used by {Ably::Modules::StateMachine} def logger channel.logger end end end