Module: NeverBlock
- Defined in:
- lib/never_block.rb,
lib/neverblock/core/pool.rb,
lib/neverblock/io/db/pool.rb,
lib/neverblock/core/reactor.rb,
lib/neverblock/io/db/connection.rb,
lib/neverblock/io/db/drivers/mysql.rb,
lib/neverblock/io/db/fibered_connection_pool.rb,
lib/neverblock/io/db/fibered_mysql_connection.rb
Defined Under Namespace
Modules: DB, Pool Classes: Fiber, FiberPool, NBError
Constant Summary collapse
- @@reactors =
{}
- @@queue =
Queue.new
- @@thread_pool =
[]
Class Method Summary collapse
- .defer(io, action, args) ⇒ Object
-
.neverblock(nb = true, &block) ⇒ Object
The given block will run its queries either in blocking or non-blocking mode based on the first parameter.
-
.neverblocking? ⇒ Boolean
Checks if we should be working in a non-blocking mode.
- .reactor ⇒ Object
- .sleep(time) ⇒ Object
- .wait(mode, io) ⇒ Object
Class Method Details
.defer(io, action, args) ⇒ Object
45 46 47 48 |
# File 'lib/neverblock/core/reactor.rb', line 45 def self.defer(io, action, args) @@queue << [io, action, args, NB::Fiber.current, NB.reactor] NB::Fiber.yield 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
16 17 18 19 20 21 |
# File 'lib/never_block.rb', line 16 def self.neverblock(nb = true, &block) status = NB::Fiber.current[:neverblock] NB::Fiber.current[:neverblock] = nb block.call NB::Fiber.current[:neverblock] = status end |
.neverblocking? ⇒ Boolean
Checks if we should be working in a non-blocking mode
10 11 12 |
# File 'lib/never_block.rb', line 10 def self.neverblocking? NB::Fiber.respond_to?(:current) && NB::Fiber.current.respond_to?('[]') && NB::Fiber.current[:neverblock] && NB.reactor.running? end |
.reactor ⇒ Object
26 27 28 |
# File 'lib/neverblock/core/reactor.rb', line 26 def self.reactor @@reactors[Thread.current.object_id] ||= ::Reactor::Base.new end |