Module: Swift::Adapter::Eventmachine

Included in:
Eventmachine::Mysql, Eventmachine::Postgres
Defined in:
lib/swift/adapter/eventmachine.rb

Defined Under Namespace

Classes: Handler, Mysql, Postgres

Instance Method Summary collapse

Instance Method Details

#execute(command, *bind) ⇒ Object

Execute a command asynchronously.

Examples:

defer = Swift.db.execute(User, "select * from users where id = ?", 1)
defer.callback do |user|
  p user.id
end
defer.errback do |error|
  p error
end

Raises:

See Also:

  • Swift::Adapter::Eventmachine.[Swift[Swift::Adapter]


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/swift/adapter/eventmachine.rb', line 43

def execute command, *bind
  raise RuntimeError, 'Command already in progress' unless pending.empty?

  record, command = command, bind.shift if command.kind_of?(Class) && command < Record
  pending << [Time.now, command, bind]
  query(command, *bind)

  ::EM::DefaultDeferrable.new.tap do |defer|
    ::EM.watch(fileno, Handler, self, record, defer) {|c| c.notify_readable = true}
  end
end

#pendingObject



55
56
57
# File 'lib/swift/adapter/eventmachine.rb', line 55

def pending
  @pending ||= []
end