<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/merb-core/dispatch/worker.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -544,9 +544,6 @@ module Merb
       @rakefiles += rakefiles
     end
 
-
-
-
   end
 end
 </diff>
      <filename>lib/merb-core.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,7 @@ module Merb
   autoload :Router,                   &quot;merb-core/dispatch/router&quot;
   autoload :SessionMixin,             &quot;merb-core/dispatch/session&quot;
   autoload :Test,                     &quot;merb-core/test&quot;
+  autoload :Worker,                   &quot;merb-core/dispatch/worker&quot;
 end
 
 # Require this rather than autoloading it so we can be sure the default template</diff>
      <filename>lib/merb-core/autoload.rb</filename>
    </modified>
    <modified>
      <diff>@@ -611,6 +611,14 @@ class Merb::BootLoader::ChooseAdapter &lt; Merb::BootLoader
   end
 end
 
+class Merb::BootLoader::StartWorkerThread &lt; Merb::BootLoader
+
+  # Choose the Rack adapter/server to use and set Merb.adapter.
+  def self.run
+    Merb::Worker.new
+  end
+end
+
 class Merb::BootLoader::RackUpApplication &lt; Merb::BootLoader
   # Setup the Merb Rack App or read a rackup file located at
   # Merb::Config[:rackup] with the same syntax as the</diff>
      <filename>lib/merb-core/bootloader.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,22 @@
 module Merb
   # Module that is mixed in to all implemented controllers.
   module ControllerMixin
+    
+    # Enqueu a block to run in a background thread outside of the request
+    # response dispatch
+    #
+    # ==== Parameters
+    # takes a block to run later
+    #
+    # ==== Example
+    # run_later do
+    #   SomeBackgroundTask.run
+    # end
+    #
+    def run_later(&amp;blk)
+      Merb::Dispatcher.work_queue &lt;&lt; blk
+    end
+    
     # Renders the block given as a parameter using chunked encoding.
     #
     # ==== Parameters</diff>
      <filename>lib/merb-core/controller/mixins/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,6 +6,12 @@ class Merb::Dispatcher
     attr_accessor :use_mutex
     
     @@mutex = Mutex.new
+    @@work_queue = Queue.new
+    
+    def work_queue 
+      @@work_queue
+    end  
+    
     Merb::Dispatcher.use_mutex = ::Merb::Config[:use_mutex]
     
     # This is where we grab the incoming request REQUEST_URI and use that in</diff>
      <filename>lib/merb-core/dispatch/dispatcher.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8ceb03e11d386feadfa9dd47b57d72c99e36ee6a</id>
    </parent>
  </parents>
  <author>
    <name>Ezra Zygmuntowicz</name>
    <email>ez@engineyard.com</email>
  </author>
  <url>http://github.com/wycats/merb-core/commit/ff42997e2a50613d37c40012b4cec623c3cc2fd5</url>
  <id>ff42997e2a50613d37c40012b4cec623c3cc2fd5</id>
  <committed-date>2008-06-23T21:13:05-07:00</committed-date>
  <authored-date>2008-06-23T21:13:05-07:00</authored-date>
  <message>Added Merb::Worker. You can now add a block to be run in a separate thread
from your merb controllers with the run_later method

run_later do
  SomeBackgroundTask.run
end

The block gets pushed onto a thread safe Queue in the Dispatcher and a
Merb::Worker class has a thread that loops over items in the queue and
calls the block. The work goes to sleep when the queue is empty and wakes
up when items are added to the queue</message>
  <tree>2d01ce2d4e363690d014714cff3431d2f71b17d0</tree>
  <committer>
    <name>Ezra Zygmuntowicz</name>
    <email>ez@engineyard.com</email>
  </committer>
</commit>
