about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rainbows.rb18
-rw-r--r--lib/rainbows/fiber/base.rb3
-rw-r--r--lib/rainbows/fiber/rev.rb6
3 files changed, 20 insertions, 7 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index 0b6402a..d3a3e7d 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -34,6 +34,24 @@ module Rainbows
 
   class << self
 
+    # Sleeps the current application dispatch.  This will pick the
+    # optimal method to sleep depending on the concurrency model chosen
+    # (which may still suck and block the entire process).  Using this
+    # with the basic :Rev or :EventMachine models is not recommended.
+    # This should be used within your Rack application.
+    def sleep(nr)
+      case G.server.use
+      when :FiberPool, :FiberSpawn
+        Rainbows::Fiber.sleep(nr)
+      when :RevFiberSpawn
+        Rainbows::Fiber::Rev::Sleeper.new(nr)
+      when :Revactor
+        Actor.sleep(nr)
+      else
+        Kernel.sleep(nr)
+      end
+    end
+
     # runs the Rainbows! HttpServer with +app+ and +options+ and does
     # not return until the server has exited.
     def run(app, options = {})
diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index 1617c54..090a9e4 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -16,7 +16,8 @@ module Rainbows
     # puts the current Fiber into uninterruptible sleep for at least
     # +seconds+.  Unlike Kernel#sleep, this it is not possible to sleep
     # indefinitely to be woken up (nobody wants that in a web server,
-    # right?).
+    # right?).  Calling this directly is deprecated, use
+    # Rainbows.sleep(seconds) instead.
     def self.sleep(seconds)
       ZZ[::Fiber.current] = Time.now + seconds
       ::Fiber.yield
diff --git a/lib/rainbows/fiber/rev.rb b/lib/rainbows/fiber/rev.rb
index 36a46d4..bd9638f 100644
--- a/lib/rainbows/fiber/rev.rb
+++ b/lib/rainbows/fiber/rev.rb
@@ -108,12 +108,6 @@ module Rainbows::Fiber
         client.close
       end
     end
-
-    # TODO: env["rainbows.sleep"]
-    def self.sleep(seconds)
-      Sleeper.new(seconds)
-    end
-
   end
 
   class IO # see rainbows/fiber/io for original definition