Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

properly determine if we're wrapped in a fiber or not. and if we're not

wrapped inside a fiber nor a thread, then we can't use em-http-request,
but rest-client with threads instead
  • Loading branch information...
commit 9d02de25410998fe1659122fb89092ae171b413a 1 parent 0edd96d
@godfat godfat authored
View
2  lib/rest-core.rb
@@ -18,6 +18,8 @@ module RestCore
TIMER = 'async.timer'
FUTURE = 'async.future'
+ RootFiber = Fiber.respond_to?(:current) && Fiber.current
+
# core utilities
autoload :Builder , 'rest-core/builder'
autoload :Client , 'rest-core/client'
View
5 lib/rest-core/engine/auto.rb
@@ -11,7 +11,10 @@ def call env, &k
def http_client
if Object.const_defined?(:EventMachine) &&
::EventMachine.const_defined?(:HttpRequest) &&
- ::EventMachine.reactor_running?
+ ::EventMachine.reactor_running? &&
+ # it should be either wrapped around a thread or a fiber
+ ((Thread.main != Thread.current) ||
+ (Fiber.respond_to?(:current) && RootFiber != Fiber.current))
@emhttprequest ||= RestCore::EmHttpRequest.new
View
4 lib/rest-core/engine/future/future.rb
@@ -15,7 +15,9 @@ def method_missing msg, *args, &block
end
def self.create *args, &block
- if Thread.current == Thread.main
+ if Fiber.respond_to?(:current) && RootFiber != Fiber.current &&
+ # because under a thread, Fiber.current won't return the root fiber
+ Thread.main == Thread.current
FutureFiber .new(*args, &block)
else
FutureThread.new(*args, &block)
Please sign in to comment.
Something went wrong with that request. Please try again.