Sha256: a73a689a29f4f4e8018d2e2c5fe6465c8445bb8cd63e96e61f97d7bf494888f2
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
swift-1.0.3 | lib/swift/synchrony.rb |