forked from igrigorik/em-http-request
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fire EM connection error at next tick
this simplifies the API A problem is that the error callback should fire before setting it up. Hence, if we are in a fiber, and if we expected to yield after setting up callbacks/errbacks. We would resume the fiber before yielding it, generating a double resume error. We work around this problem by calling :close/:on_error at next tick. Hence, the errback's fiber will predictably be EM's reactor fiber.
- Loading branch information
1 parent
235c69a
commit eafe3d4
Showing
3 changed files
with
33 additions
and
4 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'helper' | ||
require 'fiber' | ||
|
||
describe EventMachine::HttpRequest do | ||
context "with fibers" do | ||
it "should be transparent to connexion errors" do | ||
EventMachine.run do | ||
Fiber.new do | ||
f = Fiber.current | ||
http = EventMachine::HttpRequest.new('http://non-existing.domain/').get | ||
http.callback {failed(http)} | ||
http.errback {f.resume} | ||
Fiber.yield | ||
EventMachine.stop | ||
end.resume | ||
end | ||
end | ||
end | ||
end | ||
|
||
|