-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
require 'eventmachine' | |||
require 'swift' | |||
|
|||
module Swift | |||
class Adapter | |||
alias :blocking_execute :execute | |||
|
|||
class EMHandler < EM::Connection | |||
attr_reader :result, :defer | |||
def initialize result, defer | |||
@result = result | |||
@defer = defer | |||
end | |||
|
|||
def notify_readable | |||
detach | |||
begin | |||
result.retrieve | |||
rescue Exception => e | |||
defer.fail(e) | |||
else | |||
defer.succeed(result) | |||
end | |||
end | |||
end | |||
|
|||
def execute *args | |||
EM::DefaultDeferrable.new.tap do |defer| | |||
EM.watch(fileno, EMHandler, async_execute(*args), defer) {|c| c.notify_readable = true } | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
require 'em-synchrony' | |||
require 'swift/eventmachine' | |||
|
|||
module Swift | |||
class Adapter | |||
alias :aexecute :execute | |||
def execute *args | |||
EM::Synchrony.sync aexecute(*args) | |||
end | |||
end | |||
end |