Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix channel detach #429

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading