Skip to content

Commit

Permalink
Rename ITaskSpecification.background_task to ITaskSpecification.task (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Jul 17, 2021
1 parent de7c81c commit e556014
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ of Traits Futures.
background task types.
* The ``state`` trait of the ``~.TraitsExecutor`` is now read-only;
previously, it was writable.
* The ``ITaskSpecification.background_task`` method has been renamed to
``task``.
* The ``ITaskSpecification.future`` method now requires a cancellation callback
to be passed.

Other Changes
~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions docs/source/guide/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Putting it all together: the task specification

The last piece we need is a task specification, which is the object that can be
submitted to the |TraitsExecutor|. This object needs to have two attributes:
``future`` and ``background_task``. Given an instance ``task`` of a task
``future`` and ``task``. Given an instance ``task`` of a task
specification, the |TraitsExecutor| calls ``task.future(cancel)``
to create the future, and ``task.background_task()`` to create the background
to create the future, and ``task.task()`` to create the background
callable. For the background task, we want to return (but not call!) the
``fizz_buzz`` function that we defined above. For the future, we create and
return a new ``FizzBuzzFuture`` instance. So our task specification
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/examples/fizz_buzz_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def future(self, cancel):
"""
return FizzBuzzFuture(_cancel=cancel)

def background_task(self):
def task(self):
"""
Return a background callable for this task specification.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/background_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def future(self, cancel):
"""
return CallFuture(_cancel=cancel)

def background_task(self):
def task(self):
"""
Return a background callable for this task specification.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/background_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def future(self, cancel):
"""
return IterationFuture(_cancel=cancel)

def background_task(self):
def task(self):
"""
Return a background callable for this task specification.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/background_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def future(self, cancel):
"""
return ProgressFuture(_cancel=cancel)

def background_task(self):
def task(self):
"""
Return a background callable for this task specification.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/i_task_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ITaskSpecification(ABC):
"""

@abstractmethod
def background_task(self):
def task(self):
"""
Return the callable that will be invoked as the background task.
Expand Down
2 changes: 1 addition & 1 deletion traits_futures/traits_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def submit(self, task):
cancel_event = self._context.event()

sender, receiver = self._message_router.pipe()
runner = task.background_task()
runner = task.task()
future = task.future(cancel_event.set)

self._worker_pool.submit(
Expand Down
6 changes: 3 additions & 3 deletions traits_futures/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def _dispatch_to_future(self, event):
self.done = True


def run_background_task(background_task, sender, cancelled):
def run_background_task(task, sender, cancelled):
"""
Wrapper for callables submitted to the underlying executor.
Parameters
----------
background_task
task
Callable representing the background task. This will be called
with arguments ``send`` and ``cancelled``.
sender : IMessageSender
Expand All @@ -69,7 +69,7 @@ def run_background_task(background_task, sender, cancelled):
"""
try:
with sender:
background_task(sender.send, cancelled)
task(sender.send, cancelled)
except BaseException:
# We'll only ever get here in the case of a coding error. But in
# case that happens, it's useful to have the exception logged to
Expand Down

0 comments on commit e556014

Please sign in to comment.