コード例 #1
0
    def on_run(self, *tasks, subtasks=(), finite=True, **kwargs):
        """
        :param tasks: Tasks to be run concurrently.
        :param subtasks: More tasks to be run concurrently.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """

        subtasks_iterable, subtasks_iterable_copy = itertools.tee(
            itertools.chain(tasks, subtasks))
        all_success = True

        for task in subtasks_iterable:
            if not should_run(task, finite):
                continue
            task()
            all_success = all_success and (not task.finished or task.success)

        if not all_success:
            self.finish(success=False)
            return

        for task in subtasks_iterable_copy:
            if not should_finish(task, finite):
                break
        else:
            self.finish()
コード例 #2
0
    def on_run(self, *args, finite=True, **kwargs):
        if should_run(self.main_task, finite):
            self.main_task()

        if should_finish(self.main_task, finite):
            if self.main_task.success:
                self.run_branch(self.on_success, finite)

            else:
                self.run_branch(self.on_fail, finite)
コード例 #3
0
ファイル: combinators.py プロジェクト: sjt85/software
    def on_run(self, master_task, *tasks, subtasks=(),
               finite: bool = True, **kwargs):
        """
        :param master_task: Task to be run concurrently and the only Task to be checked for finishing.
        :param tasks: Tasks to be run concurrently.
        :param subtasks: More tasks to be run concurrently.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """
        self.master_task = master_task
        self.concurrent(master_task, *tasks, *subtasks, finite=finite)

        if should_finish(master_task, finite):
            self.finish()
コード例 #4
0
    def on_run(self, master_task, *tasks, subtasks=(),
               finite: bool = True, **kwargs):
        """
        :param master_task: Task to be run concurrently and the only Task to be checked for finishing.
        :param tasks: Tasks to be run concurrently.
        :param subtasks: More tasks to be run concurrently.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """
        self.master_task = master_task
        self.concurrent(master_task, *(tasks + subtasks), finite=finite)

        for t in [self.concurrent, self.master_task]:
            if should_finish(t, finite):
                self.finish(success=t.success)
                break
コード例 #5
0
ファイル: combinators.py プロジェクト: sjt85/software
    def on_run(self, *tasks, subtasks=(), finite=True, **kwargs):
        """
        :param tasks: Tasks to be run concurrently.
        :param subtasks: More tasks to be run concurrently.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """
        subtasks_iterable, subtasks_iterable_copy = itertools.tee(itertools.chain(tasks, subtasks))

        for task in subtasks_iterable:
            if finite and task.has_ever_finished:
                continue
            task()

        for task in subtasks_iterable_copy:
            if not should_finish(task, finite):
                break
        else:
            self.finish()
コード例 #6
0
 def run_branch(self, branch, finite):
     if should_run(branch, finite):
         branch()
     if should_finish(branch, finite):
         self.finish(success=branch.success)