Skip to content

Commit

Permalink
pybricks.tools.Task: Rename to multitask.
Browse files Browse the repository at this point in the history
This makes it look like an async function, which is closer to the would-be Python implementation.
  • Loading branch information
laurensvalk committed May 8, 2023
1 parent feee5e7 commit 436738d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pybricks/tools/pb_module_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ STATIC const mp_rom_map_elem_t tools_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_wait), MP_ROM_PTR(&pb_module_tools_wait_obj) },
{ MP_ROM_QSTR(MP_QSTR_run_task), MP_ROM_PTR(&pb_module_tools_run_task_obj) },
{ MP_ROM_QSTR(MP_QSTR_StopWatch), MP_ROM_PTR(&pb_type_StopWatch) },
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&pb_type_Task) },
{ MP_ROM_QSTR(MP_QSTR_multitask), MP_ROM_PTR(&pb_type_Task) },
#if MICROPY_PY_BUILTINS_FLOAT
{ MP_ROM_QSTR(MP_QSTR_Matrix), MP_ROM_PTR(&pb_type_Matrix) },
{ MP_ROM_QSTR(MP_QSTR_vector), MP_ROM_PTR(&pb_geometry_vector_obj) },
Expand Down
10 changes: 5 additions & 5 deletions tests/virtualhub/multitasking/basic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pybricks.tools import Task, run_task
from pybricks.tools import multitask, run_task


class CallCounter:
Expand Down Expand Up @@ -55,7 +55,7 @@ async def test_all_1():
task2 = return_after(2, task2_cancel)

# should return [0, 1] - both allowed to complete
print(await Task(task1, task2))
print(await multitask(task1, task2))

# neither should be canceled
print(task1_cancel.count, task2_cancel.count)
Expand Down Expand Up @@ -84,7 +84,7 @@ async def test_all_2():

# should throw RuntimeError("task2")
try:
await Task(task1, task2)
await multitask(task1, task2)
except Exception as e:
print(type(e), e.args)

Expand Down Expand Up @@ -114,7 +114,7 @@ async def test_race_1():
task2 = return_after(2, task2_cancel)

# returns [0, None] - only first completes
print(await Task(task1, task2, race=True))
print(await multitask(task1, task2, race=True))

# task2 should be canceled
print(task1_cancel.count, task2_cancel.count)
Expand Down Expand Up @@ -143,7 +143,7 @@ async def test_race_2():

# should throw RuntimeError("task2")
try:
await Task(task1, task2, race=True)
await multitask(task1, task2, race=True)
except Exception as e:
print(type(e), e.args)

Expand Down
4 changes: 2 additions & 2 deletions tests/virtualhub/multitasking/motor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Direction
from pybricks.robotics import DriveBase
from pybricks.tools import wait, Task, run_task
from pybricks.tools import wait, multitask, run_task

# Initialize devices as usual.
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
Expand Down Expand Up @@ -37,7 +37,7 @@ async def hello(name):
# This is the main program
async def main():
print("Running multiple tasks at once!")
await Task(square(), center(), hello("Pybricks"))
await multitask(square(), center(), hello("Pybricks"))
print("You can also just run one task.")
await hello("World!")

Expand Down

0 comments on commit 436738d

Please sign in to comment.