Skip to content

Commit 51ae360

Browse files
committed
♻️ Add command response handler before command is sent
As far as I can tell, this really isn't necessary: there is no race condition because the `synchronize` mutex will not be released before the response handler is added. Nor is it sufficient to protect against any invalid responses sent previously. But the code _reads_ more cleanly (to me) when it is written so the critical window that requires that mutex is as short as possible.
1 parent 24d5c77 commit 51ae360

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

lib/net/imap.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,20 +3639,14 @@ def send_command(cmd, *args, &block)
36393639
put_string(" ")
36403640
send_data(i, tag)
36413641
end
3642+
@logout_command_tag = tag if cmd == "LOGOUT"
36423643
guard_against_tagged_response_skipping_handler!(tag, cmd)
3643-
put_string(CRLF)
3644-
if cmd == "LOGOUT"
3645-
@logout_command_tag = tag
3646-
end
3647-
if block
3648-
add_response_handler(&block)
3649-
end
3644+
add_response_handler(&block) if block
36503645
begin
3651-
return get_tagged_response(tag, cmd)
3646+
put_string(CRLF)
3647+
get_tagged_response(tag, cmd)
36523648
ensure
3653-
if block
3654-
remove_response_handler(block)
3655-
end
3649+
remove_response_handler(block) if block
36563650
end
36573651
end
36583652
rescue InvalidResponseError

0 commit comments

Comments
 (0)