Sha256: 6f2deff5c226ea72b9a894c778fb4a1395fc98079114dc9abf01f92b61a7d967
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
require 'em-synchrony' require 'swift/eventmachine' module Swift # em-synchrony support for Swift::Adapter # # This replaces the default Adapter#execute with a version that uses EM::Synchrony.sync to wait for the # defered command to complete. It assumes that the execute method is called inside a em-synchrony Fiber. class Adapter alias :aexecute :execute # Execute a command asynchronously and pause the Fiber until the command finishes. # # @example # EM.run do # 3.times.each do |n| # EM.synchrony do # db = Swift.setup(:default, Swift::Adapter::Postgres, db: "swift_test") # result = db.execute("select pg_sleep(3 - #{n}), #{n + 1} as qid") # # p result.first # EM.stop if n == 0 # end # end # end # # @see [Swift::Adapter] def execute *args res = EM::Synchrony.sync aexecute(*args) raise res if res.kind_of?(Error) yield res if block_given? res rescue => e $stderr.puts e, e.backtrace.join($/) nil end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
swift-1.0.2 | lib/swift/synchrony.rb |
swift-1.0.1 | lib/swift/synchrony.rb |
swift-1.0.0 | lib/swift/synchrony.rb |