Sha256: 25cda51e25a7f46621993c228e4a87ec7379b8171bcf66f797f0e71d6d44ebfa

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

begin
  require "mongo/connection"
rescue LoadError => error
  raise "Missing EM-Synchrony dependency: gem install mongo"
end

# monkey-patch Mongo to use em-synchrony's socket and thread classs
silence_warnings do
  class Mongo::Connection
    TCPSocket = ::EventMachine::Synchrony::TCPSocket
    Mutex = ::EventMachine::Synchrony::Thread::Mutex
    ConditionVariable = ::EventMachine::Synchrony::Thread::ConditionVariable
  end

  class Mongo::Pool
    TCPSocket = ::EventMachine::Synchrony::TCPSocket
    Mutex = ::EventMachine::Synchrony::Thread::Mutex
    ConditionVariable = ::EventMachine::Synchrony::Thread::ConditionVariable
  end

  class EventMachine::Synchrony::MongoTimeoutHandler
    def self.timeout(op_timeout, ex_class, &block)
      f = Fiber.current
      timer = EM::Timer.new(op_timeout) { f.resume(nil) }
      res = block.call
      timer.cancel
      res
    end
  end

  Mongo::TimeoutHandler = EventMachine::Synchrony::MongoTimeoutHandler
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-synchrony-1.0.0 lib/em-synchrony/mongo.rb