def next(self, timeout=None, task=<NUM_LIT:0>, block=True):
<EOL>if not self._started.isSet():<EOL><INDENT>log.debug('<STR_LIT>' % self)<EOL>raise RuntimeError('<STR_LIT>' % self)<EOL><DEDENT>elif self._task_finished[task].isSet():<EOL><INDENT>log.debug('<STR_LIT>' % (self, task))<EOL>raise StopIteration<EOL><DEDENT>try:<EOL><INDENT>log.debug('<STR_LIT>' %(self, self.ordered, task))<EOL>if self.ordered:<EOL><INDENT>_got_next =self._next_available[task].get(timeout=timeout, block=block)<EOL>log.debug('<STR_LIT>' % (self, task))<EOL>result = self._task_results[task].get()<EOL><DEDENT>else:<EOL><INDENT>result =self._task_results[task].get(timeout=timeout, block=block)<EOL><DEDENT><DEDENT>except Empty:<EOL><INDENT>self._task_next_lock[task].acquire()<EOL>log.debug('<STR_LIT>' %(self, self.ordered, task))<EOL>try:<EOL><INDENT>if self.ordered:<EOL><INDENT>_got_next = self._next_available[task].get(block=False)<EOL>log.debug('<STR_LIT>' %(self, task))<EOL>result = self._task_results[task].get()<EOL><DEDENT>else:<EOL><INDENT>result = self._task_results[task].get(block=False)<EOL><DEDENT><DEDENT>except Empty:<EOL><INDENT>if self.skip:<EOL><INDENT>self._next_skipped[task] += <NUM_LIT:1><EOL>self._pool_semaphore.release()<EOL><DEDENT>self._task_next_lock[task].release()<EOL>raise TimeoutError('<STR_LIT>' %(self, self.ordered, task))<EOL><DEDENT><DEDENT>log.debug('<STR_LIT>' %(self, self.ordered, task, result))<EOL>index, is_valid, real_result = result<EOL>if index == '<STR_LIT>':<EOL><INDENT>self._task_finished[task].set()<EOL>log.debug('<STR_LIT>' %(self, task))<EOL>self._pool_semaphore.release()<EOL>log.debug('<STR_LIT>' %(self, task))<EOL>raise StopIteration<EOL><DEDENT>if task in self._tasks_tracked:<EOL><INDENT>self._tasks_tracked[task][index] = real_result<EOL><DEDENT>if is_valid:<EOL><INDENT>log.debug('<STR_LIT>' % (self, index, task))<EOL>self._pool_semaphore.release()<EOL>return real_result<EOL><DEDENT>else:<EOL><INDENT>log.debug('<STR_LIT>' % (self, index, task))<EOL>self._pool_semaphore.release()<EOL>raise real_result<EOL><DEDENT>
Returns the next result for the given **task**. Defaults to ``0``, which
is the first **task**. If multiple chained tasks are evaluated then the
next method of only the last should be called directly. 

Arguments:

  - timeout (``float``) Number of seconds to wait until a 
    ``TimeoutError`` is raised.
  - task (``int``) id of the task from the ``NuMap`` instance
  - block (``bool``) if ``True`` call will block until result is 
    available