Skip to content

Commit

Permalink
Fixed channel detach implementation, updated according to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Jul 8, 2024
1 parent 1596829 commit 73ede0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
10 changes: 5 additions & 5 deletions lib/ably/realtime/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,22 @@ def attach(&success_block)
# @return [Ably::Util::SafeDeferrable] Deferrable that supports both success (callback) and failure (errback) callback
#
def detach(&success_block)
if initialized?
if initialized? || detached? # RTL5a
success_block.call if block_given?
return Ably::Util::SafeDeferrable.new_and_succeed_immediately(logger)
end

if failed? || connection.closing? || connection.failed?
if failed? || connection.closing? || connection.failed? # RTL5b, RTL5g
return Ably::Util::SafeDeferrable.new_and_fail_immediately(logger, exception_for_state_change_to(:detaching))
end

if !detached?
if attaching?
connection.once_or_if :connected do # RTL5h
if attaching? || detaching?
# Let the pending operation complete (#RTL5i)
once_state_changed { transition_state_machine :detaching if can_transition_to?(:detaching) }
elsif can_transition_to?(:detaching)
transition_state_machine :detaching
else
else # RTL5j
transition_state_machine! :detached
end
end
Expand Down
23 changes: 4 additions & 19 deletions lib/ably/realtime/channel/channel_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,10 @@ def send_detach_protocol_message(previous_state)
end
end

on_disconnected_and_connected = lambda do
connection.unsafe_once(:disconnected) do
connection.unsafe_once(:connected) do
yield if pending_state_change_timer
end if pending_state_change_timer
end
end

send_detach_message = lambda do
on_disconnected_and_connected.call do
send_detach_message.call
end
connection.send_protocol_message(
action: detach_action.to_i,
channel: channel.name
)
end

send_detach_message.call
connection.send_protocol_message_immediately(
action: detach_action.to_i,
channel: channel.name
)
end

def logger
Expand Down

0 comments on commit 73ede0b

Please sign in to comment.