text: <!DOCTYPE html>
  
  <html>
  <head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  
  <title>class Celluloid::Task - celluloid-0.15.2 Documentation</title>
  
  <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">
  
  <script type="text/javascript">
    var rdoc_rel_prefix = "../";
  </script>
  
  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
  <script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
  <script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
  <script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
  <script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
  <script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>
  
  
  <body id="top" class="class">
  <nav id="metadata">
    <nav id="home-section" class="section">
    <h3 class="section-header">
      <a href="../index.html">Home</a>
      <a href="../table_of_contents.html#classes">Classes</a>
      <a href="../table_of_contents.html#methods">Methods</a>
    </h3>
  </nav>
  
  
    <nav id="search-section" class="section project-section" class="initially-hidden">
    <form action="#" method="get" accept-charset="utf-8">
      <h3 class="section-header">
        <input type="text" name="search" placeholder="Search" id="search-field"
               title="Type to search, Up and Down to navigate, Enter to load">
      </h3>
    </form>
  
    <ul id="search-results" class="initially-hidden"></ul>
  </nav>
  
  
    
  
    <div id="file-metadata">
      <nav id="file-list-section" class="section">
    <h3 class="section-header">Defined In</h3>
    <ul>
      <li>lib/celluloid/tasks.rb
      <li>lib/celluloid/tasks/task_thread.rb
    </ul>
  </nav>
  
      
    </div>
  
    <div id="class-metadata">
      
      <nav id="parent-class-section" class="section">
    <h3 class="section-header">Parent</h3>
    
    <p class="link">Object
    
  </nav>
  
      
      
      <!-- Method Quickref -->
  <nav id="method-list-section" class="section">
    <h3 class="section-header">Methods</h3>
  
    <ul class="link-list">
      
      <li ><a href="#method-c-current">::current</a>
      
      <li ><a href="#method-c-new">::new</a>
      
      <li ><a href="#method-c-suspend">::suspend</a>
      
      <li ><a href="#method-i-backtrace">#backtrace</a>
      
      <li ><a href="#method-i-create">#create</a>
      
      <li ><a href="#method-i-exclusive">#exclusive</a>
      
      <li ><a href="#method-i-exclusive-3F">#exclusive?</a>
      
      <li ><a href="#method-i-guard">#guard</a>
      
      <li ><a href="#method-i-inspect">#inspect</a>
      
      <li ><a href="#method-i-resume">#resume</a>
      
      <li ><a href="#method-i-running-3F">#running?</a>
      
      <li ><a href="#method-i-suspend">#suspend</a>
      
      <li ><a href="#method-i-terminate">#terminate</a>
      
    </ul>
  </nav>
  
    </div>
  
    <div id="project-metadata">
      
      <nav id="classindex-section" class="section project-section">
    <h3 class="section-header">Class and Module Index</h3>
  
    <ul class="link-list">
    
      <li><a href="../Celluloid.html">Celluloid</a>
    
      <li><a href="../Celluloid/AbortError.html">Celluloid::AbortError</a>
    
      <li><a href="../Celluloid/AbstractProxy.html">Celluloid::AbstractProxy</a>
    
      <li><a href="../Celluloid/Actor.html">Celluloid::Actor</a>
    
      <li><a href="../Celluloid/Actor/Sleeper.html">Celluloid::Actor::Sleeper</a>
    
      <li><a href="../Celluloid/ActorProxy.html">Celluloid::ActorProxy</a>
    
      <li><a href="../Celluloid/AsyncCall.html">Celluloid::AsyncCall</a>
    
      <li><a href="../Celluloid/AsyncProxy.html">Celluloid::AsyncProxy</a>
    
      <li><a href="../Celluloid/BlockCall.html">Celluloid::BlockCall</a>
    
      <li><a href="../Celluloid/BlockProxy.html">Celluloid::BlockProxy</a>
    
      <li><a href="../Celluloid/BlockResponse.html">Celluloid::BlockResponse</a>
    
      <li><a href="../Celluloid/CPUCounter.html">Celluloid::CPUCounter</a>
    
      <li><a href="../Celluloid/CPUCounter/RbConfig.html">Celluloid::CPUCounter::RbConfig</a>
    
      <li><a href="../Celluloid/Call.html">Celluloid::Call</a>
    
      <li><a href="../Celluloid/CallChain.html">Celluloid::CallChain</a>
    
      <li><a href="../Celluloid/ClassMethods.html">Celluloid::ClassMethods</a>
    
      <li><a href="../Celluloid/Condition.html">Celluloid::Condition</a>
    
      <li><a href="../Celluloid/Condition/Waiter.html">Celluloid::Condition::Waiter</a>
    
      <li><a href="../Celluloid/ConditionError.html">Celluloid::ConditionError</a>
    
      <li><a href="../Celluloid/DeadActorError.html">Celluloid::DeadActorError</a>
    
      <li><a href="../Celluloid/DeadTaskError.html">Celluloid::DeadTaskError</a>
    
      <li><a href="../Celluloid/ErrorResponse.html">Celluloid::ErrorResponse</a>
    
      <li><a href="../Celluloid/EventedMailbox.html">Celluloid::EventedMailbox</a>
    
      <li><a href="../Celluloid/ExitEvent.html">Celluloid::ExitEvent</a>
    
      <li><a href="../Celluloid/FSM.html">Celluloid::FSM</a>
    
      <li><a href="../Celluloid/FSM/ClassMethods.html">Celluloid::FSM::ClassMethods</a>
    
      <li><a href="../Celluloid/FSM/State.html">Celluloid::FSM::State</a>
    
      <li><a href="../Celluloid/FSM/UnattachedError.html">Celluloid::FSM::UnattachedError</a>
    
      <li><a href="../Celluloid/FiberStackError.html">Celluloid::FiberStackError</a>
    
      <li><a href="../Celluloid/Future.html">Celluloid::Future</a>
    
      <li><a href="../Celluloid/Future/Result.html">Celluloid::Future::Result</a>
    
      <li><a href="../Celluloid/FutureProxy.html">Celluloid::FutureProxy</a>
    
      <li><a href="../Celluloid/Incident.html">Celluloid::Incident</a>
    
      <li><a href="../Celluloid/IncidentLogger.html">Celluloid::IncidentLogger</a>
    
      <li><a href="../Celluloid/IncidentLogger/Severity.html">Celluloid::IncidentLogger::Severity</a>
    
      <li><a href="../Celluloid/IncidentReporter.html">Celluloid::IncidentReporter</a>
    
      <li><a href="../Celluloid/IncidentReporter/Formatter.html">Celluloid::IncidentReporter::Formatter</a>
    
      <li><a href="../Celluloid/InstanceMethods.html">Celluloid::InstanceMethods</a>
    
      <li><a href="../Celluloid/InternalPool.html">Celluloid::InternalPool</a>
    
      <li><a href="../Celluloid/LinkingRequest.html">Celluloid::LinkingRequest</a>
    
      <li><a href="../Celluloid/LinkingResponse.html">Celluloid::LinkingResponse</a>
    
      <li><a href="../Celluloid/Links.html">Celluloid::Links</a>
    
      <li><a href="../Celluloid/LogEvent.html">Celluloid::LogEvent</a>
    
      <li><a href="../Celluloid/Logger.html">Celluloid::Logger</a>
    
      <li><a href="../Celluloid/Mailbox.html">Celluloid::Mailbox</a>
    
      <li><a href="../Celluloid/MailboxDead.html">Celluloid::MailboxDead</a>
    
      <li><a href="../Celluloid/MailboxShutdown.html">Celluloid::MailboxShutdown</a>
    
      <li><a href="../Celluloid/Method.html">Celluloid::Method</a>
    
      <li><a href="../Celluloid/NamingRequest.html">Celluloid::NamingRequest</a>
    
      <li><a href="../Celluloid/NotActorError.html">Celluloid::NotActorError</a>
    
      <li><a href="../Celluloid/NotTaskError.html">Celluloid::NotTaskError</a>
    
      <li><a href="../Celluloid/Notifications.html">Celluloid::Notifications</a>
    
      <li><a href="../Celluloid/Notifications/Fanout.html">Celluloid::Notifications::Fanout</a>
    
      <li><a href="../Celluloid/Notifications/Subscriber.html">Celluloid::Notifications::Subscriber</a>
    
      <li><a href="../Celluloid/PoolManager.html">Celluloid::PoolManager</a>
    
      <li><a href="../Celluloid/Properties.html">Celluloid::Properties</a>
    
      <li><a href="../Celluloid/Receiver.html">Celluloid::Receiver</a>
    
      <li><a href="../Celluloid/Receivers.html">Celluloid::Receivers</a>
    
      <li><a href="../Celluloid/Registry.html">Celluloid::Registry</a>
    
      <li><a href="../Celluloid/Registry/actor;.html">Celluloid::Registry::actor;</a>
    
      <li><a href="../Celluloid/Response.html">Celluloid::Response</a>
    
      <li><a href="../Celluloid/ResumableError.html">Celluloid::ResumableError</a>
    
      <li><a href="../Celluloid/RingBuffer.html">Celluloid::RingBuffer</a>
    
      <li><a href="../Celluloid/SignalConditionRequest.html">Celluloid::SignalConditionRequest</a>
    
      <li><a href="../Celluloid/Signals.html">Celluloid::Signals</a>
    
      <li><a href="../Celluloid/StackDump.html">Celluloid::StackDump</a>
    
      <li><a href="../Celluloid/StackDump/ActorState.html">Celluloid::StackDump::ActorState</a>
    
      <li><a href="../Celluloid/StackDump/DisplayBacktrace.html">Celluloid::StackDump::DisplayBacktrace</a>
    
      <li><a href="../Celluloid/StackDump/TaskState.html">Celluloid::StackDump::TaskState</a>
    
      <li><a href="../Celluloid/StackDump/ThreadState.html">Celluloid::StackDump::ThreadState</a>
    
      <li><a href="../Celluloid/SuccessResponse.html">Celluloid::SuccessResponse</a>
    
      <li><a href="../Celluloid/SupervisionGroup.html">Celluloid::SupervisionGroup</a>
    
      <li><a href="../Celluloid/SupervisionGroup/Member.html">Celluloid::SupervisionGroup::Member</a>
    
      <li><a href="../Celluloid/Supervisor.html">Celluloid::Supervisor</a>
    
      <li><a href="../Celluloid/SyncCall.html">Celluloid::SyncCall</a>
    
      <li><a href="../Celluloid/SyncProxy.html">Celluloid::SyncProxy</a>
    
      <li><a href="../Celluloid/SystemEvent.html">Celluloid::SystemEvent</a>
    
      <li><a href="../Celluloid/Task.html">Celluloid::Task</a>
    
      <li><a href="../Celluloid/Task/TerminatedError.html">Celluloid::Task::TerminatedError</a>
    
      <li><a href="../Celluloid/Task/TimeoutError.html">Celluloid::Task::TimeoutError</a>
    
      <li><a href="../Celluloid/TaskFiber.html">Celluloid::TaskFiber</a>
    
      <li><a href="../Celluloid/TaskSet.html">Celluloid::TaskSet</a>
    
      <li><a href="../Celluloid/TaskThread.html">Celluloid::TaskThread</a>
    
      <li><a href="../Celluloid/TerminationRequest.html">Celluloid::TerminationRequest</a>
    
      <li><a href="../Celluloid/Thread.html">Celluloid::Thread</a>
    
      <li><a href="../Celluloid/ThreadHandle.html">Celluloid::ThreadHandle</a>
    
      <li><a href="../Celluloid/TimeoutError.html">Celluloid::TimeoutError</a>
    
      <li><a href="../Celluloid/UUID.html">Celluloid::UUID</a>
    
      <li><a href="../Fiber.html">Fiber</a>
    
      <li><a href="../Thread.html">Thread</a>
    
      <li><a href="../org.html">org</a>
    
      <li><a href="../org/jruby.html">org::jruby</a>
    
      <li><a href="../org/jruby/ext.html">org::jruby::ext</a>
    
      <li><a href="../org/jruby/ext/fiber.html">org::jruby::ext::fiber</a>
    
      <li><a href="../org/jruby/ext/fiber/ThreadFiber.html">org::jruby::ext::fiber::ThreadFiber</a>
    
    </ul>
  </nav>
  
    </div>
  </nav>
  
  <div id="documentation">
    <h1 class="class">class Celluloid::Task</h1>
  
    <div id="description" class="description">
      
  <p>Tasks are interruptable/resumable execution contexts used to run methods</p>
  
    </div><!-- description -->
  
    
    
    
    <section id="5Buntitled-5D" class="documentation-section">
      
  
      
  
      
  
      
      <!-- Attributes -->
      <section id="attribute-method-details" class="method-section section">
        <h3 class="section-header">Attributes</h3>
  
        
        <div id="attribute-i-chain_id" class="method-detail">
          <div class="method-heading attribute-method-heading">
            <span class="method-name">chain_id</span><span
              class="attribute-access-type">[RW]</span>
          </div>
  
          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="attribute-i-guard_warnings" class="method-detail">
          <div class="method-heading attribute-method-heading">
            <span class="method-name">guard_warnings</span><span
              class="attribute-access-type">[RW]</span>
          </div>
  
          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="attribute-i-meta" class="method-detail">
          <div class="method-heading attribute-method-heading">
            <span class="method-name">meta</span><span
              class="attribute-access-type">[R]</span>
          </div>
  
          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="attribute-i-status" class="method-detail">
          <div class="method-heading attribute-method-heading">
            <span class="method-name">status</span><span
              class="attribute-access-type">[R]</span>
          </div>
  
          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="attribute-i-type" class="method-detail">
          <div class="method-heading attribute-method-heading">
            <span class="method-name">type</span><span
              class="attribute-access-type">[R]</span>
          </div>
  
          <div class="method-description">
          
          
          
          </div>
        </div>
        
      </section><!-- attribute-method-details -->
      
  
      <!-- Methods -->
      
       <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>
  
      
        <div id="method-c-current" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">current</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Obtain the current task</p>
            
            
  
            
            <div class="method-source-code" id="current-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 18</span>
  <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">current</span>
    <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:celluloid_task</span>] <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotTaskError</span>, <span class="ruby-string">&quot;not within a task context&quot;</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- current-source -->
            
          </div>
  
          
  
          
        </div><!-- current-method -->
  
      
        <div id="method-c-new" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">(type, meta) { || ... }</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Create a new task</p>
            
            
  
            
            <div class="method-source-code" id="new-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 31</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">meta</span>)
    <span class="ruby-ivar">@type</span>     = <span class="ruby-identifier">type</span>
    <span class="ruby-ivar">@meta</span>     = <span class="ruby-identifier">meta</span>
    <span class="ruby-ivar">@status</span>   = <span class="ruby-value">:new</span>
  
    <span class="ruby-ivar">@exclusive</span>         = <span class="ruby-keyword">false</span>
    <span class="ruby-ivar">@dangerous_suspend</span> = <span class="ruby-ivar">@meta</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@meta</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:dangerous_suspend</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
    <span class="ruby-ivar">@guard_warnings</span>    = <span class="ruby-keyword">false</span>
  
    <span class="ruby-identifier">actor</span>     = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:celluloid_actor</span>]
    <span class="ruby-ivar">@chain_id</span> = <span class="ruby-constant">CallChain</span>.<span class="ruby-identifier">current_id</span>
  
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotActorError</span>, <span class="ruby-string">&quot;can&#39;t create tasks outside of actors&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">actor</span>
    <span class="ruby-identifier">guard</span> <span class="ruby-string">&quot;can&#39;t create tasks inside of tasks&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:celluloid_task</span>]
  
    <span class="ruby-identifier">create</span> <span class="ruby-keyword">do</span>
      <span class="ruby-keyword">begin</span>
        <span class="ruby-ivar">@status</span> = <span class="ruby-value">:running</span>
        <span class="ruby-identifier">actor</span>.<span class="ruby-identifier">setup_thread</span>
  
        <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:celluloid_task</span>] = <span class="ruby-keyword">self</span>
        <span class="ruby-constant">CallChain</span>.<span class="ruby-identifier">current_id</span> = <span class="ruby-ivar">@chain_id</span>
  
        <span class="ruby-identifier">actor</span>.<span class="ruby-identifier">tasks</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword">self</span>
        <span class="ruby-keyword">yield</span>
      <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Task</span><span class="ruby-operator">::</span><span class="ruby-constant">TerminatedError</span>
        <span class="ruby-comment"># Task was explicitly terminated</span>
      <span class="ruby-keyword">ensure</span>
        <span class="ruby-ivar">@status</span> = <span class="ruby-value">:dead</span>
        <span class="ruby-identifier">actor</span>.<span class="ruby-identifier">tasks</span>.<span class="ruby-identifier">delete</span> <span class="ruby-keyword">self</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>
  
          
  
          
        </div><!-- new-method -->
  
      
        <div id="method-c-suspend" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">suspend</span><span
              class="method-args">(status)</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Suspend the running task, deferring to the scheduler</p>
            
            
  
            
            <div class="method-source-code" id="suspend-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 23</span>
  <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">suspend</span>(<span class="ruby-identifier">status</span>)
    <span class="ruby-constant">Task</span>.<span class="ruby-identifier">current</span>.<span class="ruby-identifier">suspend</span>(<span class="ruby-identifier">status</span>)
  <span class="ruby-keyword">end</span></pre>
            </div><!-- suspend-source -->
            
          </div>
  
          
  
          
        </div><!-- suspend-method -->
  
      
      </section><!-- public-class-method-details -->
    
       <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>
  
      
        <div id="method-i-backtrace" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">backtrace</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            
            
            
  
            
            <div class="method-source-code" id="backtrace-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 135</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">backtrace</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- backtrace-source -->
            
          </div>
  
          
  
          
        </div><!-- backtrace-method -->
  
      
        <div id="method-i-create" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">create</span><span
              class="method-args">(&block)</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            
            
            
  
            
            <div class="method-source-code" id="create-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 65</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Implement #{self.class}#create&quot;</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- create-source -->
            
          </div>
  
          
  
          
        </div><!-- create-method -->
  
      
        <div id="method-i-exclusive" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">exclusive</span><span
              class="method-args">() { || ... }</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Execute a code block in exclusive mode.</p>
            
            
  
            
            <div class="method-source-code" id="exclusive-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 103</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">exclusive</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@exclusive</span>
      <span class="ruby-keyword">yield</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-keyword">begin</span>
        <span class="ruby-ivar">@exclusive</span> = <span class="ruby-keyword">true</span>
        <span class="ruby-keyword">yield</span>
      <span class="ruby-keyword">ensure</span>
        <span class="ruby-ivar">@exclusive</span> = <span class="ruby-keyword">false</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- exclusive-source -->
            
          </div>
  
          
  
          
        </div><!-- exclusive-method -->
  
      
        <div id="method-i-exclusive-3F" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">exclusive?</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Is this task running in exclusive mode?</p>
            
            
  
            
            <div class="method-source-code" id="exclusive-3F-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 131</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">exclusive?</span>
    <span class="ruby-ivar">@exclusive</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- exclusive-3F-source -->
            
          </div>
  
          
  
          
        </div><!-- exclusive-3F-method -->
  
      
        <div id="method-i-guard" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">guard</span><span
              class="method-args">(message)</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            
            
            
  
            
            <div class="method-source-code" id="guard-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 146</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">guard</span>(<span class="ruby-identifier">message</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@guard_warnings</span>
      <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">warn</span> <span class="ruby-identifier">message</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">$CELLULOID_DEBUG</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-identifier">message</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">$CELLULOID_DEBUG</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- guard-source -->
            
          </div>
  
          
  
          
        </div><!-- guard-method -->
  
      
        <div id="method-i-inspect" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">inspect</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Nicer string inspect for tasks</p>
            
            
  
            
            <div class="method-source-code" id="inspect-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 142</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">inspect</span>
    <span class="ruby-node">&quot;#&lt;#{self.class}:0x#{object_id.to_s(16)} @type=#{@type.inspect}, @meta=#{@meta.inspect}, @status=#{@status.inspect}&gt;&quot;</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- inspect-source -->
            
          </div>
  
          
  
          
        </div><!-- inspect-method -->
  
      
        <div id="method-i-resume" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">resume</span><span
              class="method-args">(value = nil)</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Resume a suspended task, giving it a value to return if needed</p>
            
            
  
            
            <div class="method-source-code" id="resume-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 96</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">resume</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword">nil</span>)
    <span class="ruby-identifier">guard</span> <span class="ruby-string">&quot;Cannot resume a task from inside of a task&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:celluloid_task</span>]
    <span class="ruby-identifier">deliver</span>(<span class="ruby-identifier">value</span>)
    <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- resume-source -->
            
          </div>
  
          
  
          
        </div><!-- resume-method -->
  
      
        <div id="method-i-running-3F" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">running?</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Is the current task still running?</p>
            
            
  
            
            <div class="method-source-code" id="running-3F-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 139</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">running?</span>; <span class="ruby-ivar">@status</span> <span class="ruby-operator">!=</span> <span class="ruby-value">:dead</span>; <span class="ruby-keyword">end</span></pre>
            </div><!-- running-3F-source -->
            
          </div>
  
          
  
          
        </div><!-- running-3F-method -->
  
      
        <div id="method-i-suspend" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">suspend</span><span
              class="method-args">(status)</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Suspend the current task, changing the status to the given argument</p>
            
            
  
            
            <div class="method-source-code" id="suspend-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 70</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">suspend</span>(<span class="ruby-identifier">status</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Cannot suspend while in exclusive mode&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">exclusive?</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Cannot suspend a task from outside of itself&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">Task</span>.<span class="ruby-identifier">current</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">self</span>
  
    <span class="ruby-ivar">@status</span> = <span class="ruby-identifier">status</span>
  
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">$CELLULOID_DEBUG</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@dangerous_suspend</span>
      <span class="ruby-identifier">warning</span> = <span class="ruby-string">&quot;Dangerously suspending task: &quot;</span>
      <span class="ruby-identifier">warning</span> <span class="ruby-operator">&lt;&lt;</span> [
        <span class="ruby-node">&quot;type=#{@type.inspect}&quot;</span>,
        <span class="ruby-node">&quot;meta=#{@meta.inspect}&quot;</span>,
        <span class="ruby-node">&quot;status=#{@status.inspect}&quot;</span>
      ].<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;, &quot;</span>)
  
      <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">warn</span> [<span class="ruby-identifier">warning</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">caller</span>[<span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">8</span>]].<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;\n\t&quot;</span>)
    <span class="ruby-keyword">end</span>
  
    <span class="ruby-identifier">value</span> = <span class="ruby-identifier">signal</span>
  
    <span class="ruby-ivar">@status</span> = <span class="ruby-value">:running</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Celluloid</span><span class="ruby-operator">::</span><span class="ruby-constant">ResumableError</span>)
  
    <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- suspend-source -->
            
          </div>
  
          
  
          
        </div><!-- suspend-method -->
  
      
        <div id="method-i-terminate" class="method-detail ">
          
          <div class="method-heading">
            <span class="method-name">terminate</span><span
              class="method-args">()</span>
            
            <span class="method-click-advice">click to toggle source</span>
            
          </div>
          
  
          <div class="method-description">
            
            <p>Terminate this task</p>
            
            
  
            
            <div class="method-source-code" id="terminate-source">
              <pre><span class="ruby-comment"># File lib/celluloid/tasks.rb, line 117</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">terminate</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Cannot terminate an exclusive task&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">exclusive?</span>
  
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">running?</span>
      <span class="ruby-constant">Celluloid</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;Terminating task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}&quot;</span>
      <span class="ruby-identifier">exception</span> = <span class="ruby-constant">Task</span><span class="ruby-operator">::</span><span class="ruby-constant">TerminatedError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;task was terminated&quot;</span>)
      <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">set_backtrace</span>(<span class="ruby-identifier">caller</span>)
      <span class="ruby-identifier">resume</span> <span class="ruby-identifier">exception</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">DeadTaskError</span>, <span class="ruby-string">&quot;task is already dead&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span></pre>
            </div><!-- terminate-source -->
            
          </div>
  
          
  
          
        </div><!-- terminate-method -->
  
      
      </section><!-- public-instance-method-details -->
    
    </section><!-- 5Buntitled-5D -->
  
  </div><!-- documentation -->
  
  
  <footer id="validator-badges">
    <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
    <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
    <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
  </footer>
  
  