Use Client#close rather than Client#cancel

Use Client#close rather than Client#cancel

From ca32197438f4490efffdf914d88c36497bc8fbfa Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Thu, 29 Nov 2018 19:25:40 -0200
Subject: [PATCH] Use Client#close rather than Client#cancel


diff --git a/lib/message_bus/client.rb b/lib/message_bus/client.rb
index 25fbecd..6eceb2c 100644
--- a/lib/message_bus/client.rb
+++ b/lib/message_bus/client.rb
@@ -55,7 +55,7 @@ class MessageBus::Client
   end
 
   # Closes the client connection
-  def cancel
+  def close
     if cleanup_timer
       # concurrency may nil cleanup timer
       cleanup_timer.cancel rescue nil
diff --git a/lib/message_bus/connection_manager.rb b/lib/message_bus/connection_manager.rb
index 8b03247..172ee0e 100644
--- a/lib/message_bus/connection_manager.rb
+++ b/lib/message_bus/connection_manager.rb
@@ -54,11 +54,11 @@ class MessageBus::ConnectionManager
     synchronize do
       existing = @clients[client.client_id]
       if existing && existing.seq > client.seq
-        client.cancel
+        client.close
       else
         if existing
           remove_client(existing)
-          existing.cancel
+          existing.close
         end
 
         @clients[client.client_id] = client
diff --git a/lib/message_bus/rack/middleware.rb b/lib/message_bus/rack/middleware.rb
index c8e434d..931be35 100644
--- a/lib/message_bus/rack/middleware.rb
+++ b/lib/message_bus/rack/middleware.rb
@@ -125,7 +125,7 @@ class MessageBus::Rack::Middleware
     backlog = client.backlog
 
     if backlog.length > 0 && !allow_chunked
-      client.cancel
+      client.close
       @bus.logger.debug "Delivering backlog #{backlog} to client #{client_id} for user #{user_id}"
       [200, headers, [self.class.backlog_to_json(backlog)]]
     elsif long_polling && env['rack.hijack'] && @bus.rack_hijack_enabled?
@@ -196,7 +196,7 @@ class MessageBus::Rack::Middleware
 
     client.cleanup_timer = @bus.timer.queue(@bus.long_polling_interval.to_f / 1000) {
       begin
-        client.cancel
+        client.close
         @connection_manager.remove_client(client)
       rescue
         @bus.logger.warn "Failed to clean up client properly: #{$!} #{$!.backtrace}"
diff --git a/spec/lib/message_bus/client_spec.rb b/spec/lib/message_bus/client_spec.rb
index ca8a30d..1bf86d9 100644
--- a/spec/lib/message_bus/client_spec.rb
+++ b/spec/lib/message_bus/client_spec.rb
@@ -77,7 +77,7 @@ describe MessageBus::Client do
       chunk2.first["data"].must_equal "a|\r\n|\r\n|b"
 
       @client << MessageBus::Message.new(3, 3, '/test', 'test3')
-      @client.cancel
+      @client.close
 
       data = r.read

GitHub