summary refs log tree commit homepage
path: root/lib/rainbows/never_block
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-26 23:16:41 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-26 23:33:22 +0000
commit6733af0546a759b73fd63880e8ef2549caf4c4f2 (patch)
tree80e9887968a53b25f6f7c6f645d8a43200801408 /lib/rainbows/never_block
parent20e8d57127f16da8e4242582dee3b99d54cbb729 (diff)
alias_method is a mess, super is superb!
Diffstat (limited to 'lib/rainbows/never_block')
-rw-r--r--lib/rainbows/never_block/core.rb15
-rw-r--r--lib/rainbows/never_block/event_machine.rb11
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/rainbows/never_block/core.rb b/lib/rainbows/never_block/core.rb
new file mode 100644
index 0000000..7188f75
--- /dev/null
+++ b/lib/rainbows/never_block/core.rb
@@ -0,0 +1,15 @@
+# -*- encoding: binary -*-
+# :enddoc:
+module Rainbows::NeverBlock::Core
+  def init_worker_process(worker)
+    super
+    o = Rainbows::O
+    pool = NB::Pool::FiberPool.new(o[:pool_size])
+    base = o[:backend].to_s.gsub!(/([a-z])([A-Z])/, '\1_\2').downcase!
+    require "rainbows/never_block/#{base}"
+    client_class = Rainbows::NeverBlock::Client
+    client_class.superclass.const_set(:APP, Rainbows::G.server.app)
+    client_class.const_set(:POOL, pool)
+    logger.info "NeverBlock/#{o[:backend]} pool_size=#{o[:pool_size]}"
+  end
+end
diff --git a/lib/rainbows/never_block/event_machine.rb b/lib/rainbows/never_block/event_machine.rb
index 0cfaa21..e201492 100644
--- a/lib/rainbows/never_block/event_machine.rb
+++ b/lib/rainbows/never_block/event_machine.rb
@@ -1,8 +1,13 @@
 # -*- encoding: binary -*-
 # :enddoc:
-module Rainbows
-  module NeverBlock
-    class Client < Rainbows::EventMachine::Client
+class Rainbows::NeverBlock::Client < Rainbows::EventMachine::Client
+  def app_call
+    POOL.spawn do
+      begin
+        super
+      rescue => e
+        handle_error(e)
+      end
     end
   end
 end