lib/swift/eventmachine.rb in swift-1.0.3 vs lib/swift/eventmachine.rb in swift-1.1.0
- old
+ new
@@ -8,18 +8,21 @@
class Adapter
alias :blocking_execute :execute
class EMHandler < EM::Connection
def initialize adapter, record, defer
+ @started = Time.now
@adapter = adapter
@record = record
@defer = defer
end
def notify_readable
detach
- @adapter.pending.shift
+ start, command, bind = @adapter.pending.shift
+ @adapter.log_command(start, command, bind) if @adapter.trace?
+
begin
@defer.succeed(@record ? Result.new(@record, @adapter.result) : @adapter.result)
rescue Exception => e
@defer.fail(e)
end
@@ -39,12 +42,12 @@
#
# @see [Swift::Adapter]
def execute command, *bind
raise RuntimeError, 'Command already in progress' unless pending.empty?
- pending << command
- start = Time.now
+ start = Time.now
record, command = command, bind.shift if command.kind_of?(Class) && command < Record
+ pending << [start, command, bind]
query(command, *bind)
EM::DefaultDeferrable.new.tap do |defer|
EM.watch(fileno, EMHandler, self, record, defer) {|c| c.notify_readable = true }
end