lib/swift/eventmachine.rb in swift-1.0.2 vs lib/swift/eventmachine.rb in swift-1.0.3
- old
+ new
@@ -15,10 +15,11 @@
@defer = defer
end
def notify_readable
detach
+ @adapter.pending.shift
begin
@defer.succeed(@record ? Result.new(@record, @adapter.result) : @adapter.result)
rescue Exception => e
@defer.fail(e)
end
@@ -36,14 +37,22 @@
# p error
# end
#
# @see [Swift::Adapter]
def execute command, *bind
- start = Time.now
+ raise RuntimeError, 'Command already in progress' unless pending.empty?
+
+ pending << command
+ start = Time.now
record, command = command, bind.shift if command.kind_of?(Class) && command < Record
query(command, *bind)
+
EM::DefaultDeferrable.new.tap do |defer|
EM.watch(fileno, EMHandler, self, record, defer) {|c| c.notify_readable = true }
end
+ end
+
+ def pending
+ @pending ||= []
end
end
end