<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -33,6 +33,10 @@ opts = OptionParser.new do |opts|
   opts.on(&quot;--initrb FILE&quot;, &quot;Path to agent initialization file (NANITE_ROOT/init.rb by default)&quot;) do |initrb|
     options[:initrb] = initrb
   end
+
+  opts.on(&quot;--single-threaded&quot;, &quot;Run all operations in one thread&quot;) do
+    options[:single_threaded] = true
+  end
 end
 
 opts.parse!</diff>
      <filename>bin/nanite-agent</filename>
    </modified>
    <modified>
      <diff>@@ -52,6 +52,8 @@ module Nanite
     # services    : list of services provided by this agent, by default
     #               all methods exposed by actors are listed
     #
+    # single_threaded: Run all operations in one thread
+    #
     # Connection options:
     #
     # vhost    : AMQP broker vhost that should be used</diff>
      <filename>lib/nanite/agent.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ module Nanite
       meth ||= :index
       actor = registry.actor_for(prefix)
 
-      @evmclass.defer(lambda {
+      operation = lambda do
         begin
           intermediate_results_proc = lambda { |*args| self.handle_intermediate_results(actor, meth, deliverable, *args) }
           args = [ deliverable.payload ]
@@ -26,13 +26,21 @@ module Nanite
         rescue Exception =&gt; e
           handle_exception(actor, meth, deliverable, e)
         end
-      }, lambda { |r|
+      end
+      
+      callback = lambda do |r|
         if deliverable.kind_of?(Request)
           r = Result.new(deliverable.token, deliverable.reply_to, r, identity)
           amq.queue(deliverable.reply_to, :no_declare =&gt; options[:secure]).publish(serializer.dump(r))
         end
-        r
-      })
+        r # For unit tests
+      end
+
+      if @options[:single_threaded]
+        @evmclass.next_tick { callback.call(operation.call) }
+      else
+        @evmclass.defer(operation, callback)
+      end
     end
 
     protected</diff>
      <filename>lib/nanite/dispatcher.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ebf578bbaa3313f6f3a2d5c6e4a6793a6fc407b0</id>
    </parent>
  </parents>
  <author>
    <name>raphael</name>
    <email>simon.raphael@gmail.com</email>
  </author>
  <url>http://github.com/ezmobius/nanite/commit/6f94559a90dd16aef75e425b6d821d0f220935d1</url>
  <id>6f94559a90dd16aef75e425b6d821d0f220935d1</id>
  <committed-date>2009-05-27T14:37:29-07:00</committed-date>
  <authored-date>2009-05-27T14:37:29-07:00</authored-date>
  <message>Added ability to run all operations in the same thread (useful if actors need to use code that is not thread safe such as ActiveRecord).</message>
  <tree>3a315c998a9f1b98e212aeea61e9c89b32fe5223</tree>
  <committer>
    <name>raphael</name>
    <email>simon.raphael@gmail.com</email>
  </committer>
</commit>
