Class: PgVersions::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_versions/pg_versions.rb

Defined Under Namespace

Classes: Subscription

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ Connection

Returns a new instance of Connection.



294
295
296
# File 'lib/pg_versions/pg_versions.rb', line 294

def initialize(connection=nil)
	@connection_thread = ConnectionThread.new(connection)
end

Instance Method Details

#bump(*channels) ⇒ Object



302
303
304
# File 'lib/pg_versions/pg_versions.rb', line 302

def bump(*channels)
	@connection_thread.request(:bump, channels)
end

#closeObject



298
299
300
# File 'lib/pg_versions/pg_versions.rb', line 298

def close()
	@connection_thread.request(:stop)
end

#read(*channels) ⇒ Object



307
308
309
# File 'lib/pg_versions/pg_versions.rb', line 307

def read(*channels)
	@connection_thread.request(:read, channels)
end

#subscribe(*channels, known: {}, batch_delay: 0.01) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/pg_versions/pg_versions.rb', line 312

def subscribe(*channels, known: {}, batch_delay: 0.01)
	subscription = Subscription.new(@connection_thread, batch_delay)
	subscription.subscribe([channels].flatten, known: known)
	if block_given?
		Thread.handle_interrupt(Object => :never) {
			begin
				Thread.handle_interrupt(Object => :immediate) {
					yield subscription
				}
			ensure
				subscription.drop
			end
		}
	else
		subscription
	end
end