Module: NeverBlock

Defined in:
lib/never_block.rb,
lib/never_block/pool/fiber_pool.rb,
lib/never_block/db/pooled_db_connection.rb,
lib/never_block/db/fibered_db_connection.rb,
lib/never_block/db/fibered_mysql_connection.rb,
lib/never_block/pool/fibered_connection_pool.rb,
lib/never_block/db/fibered_postgres_connection.rb

Defined Under Namespace

Modules: DB, Pool Classes: NBError

Class Method Summary collapse

Class Method Details

.event_loop_available?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/never_block.rb', line 83

def self.event_loop_available?
  defined?(EM) && EM.reactor_running?
end

.neverblock(nb = true, &block) ⇒ Object

The given block will run its queries either in blocking or non-blocking mode based on the first parameter



89
90
91
92
93
94
# File 'lib/never_block.rb', line 89

def self.neverblock(nb = true, &block)
  status = Fiber.current[:neverblock]
  Fiber.current[:neverblock] = nb
  block.call
  Fiber.current[:neverblock] = status
end

.neverblocking?Boolean

Checks if we should be working in a non-blocking mode

Returns:

  • (Boolean)


79
80
81
# File 'lib/never_block.rb', line 79

def self.neverblocking?
  Fiber.respond_to?(:current) && Fiber.current[:neverblock]
end