about summary refs log tree commit homepage
path: root/lib/rainbows.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-22 01:22:32 -0800
committerEric Wong <normalperson@yhbt.net>2009-12-22 13:05:30 -0800
commitfa622de470d475f0afc94cb619cc69e7e127830c (patch)
tree90e7f20bd857bd2db08117029e913627cda2774c /lib/rainbows.rb
parentcdac4e6b8847754421c6f65baab2ac9a105d746a (diff)
downloadrainbows-fa622de470d475f0afc94cb619cc69e7e127830c.tar.gz
We'll export this across the board to all Rack applications
to sleep with.  This provides the optimum method of sleeping
regardless of the concurrency model you choose.  This method
is still highly not recommended for pure event-driven models
like Rev or EventMachine (but the threaded/fiber/actor-based
variants are fine).
Diffstat (limited to 'lib/rainbows.rb')
-rw-r--r--lib/rainbows.rb18
1 files changed, 18 insertions, 0 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 = {})