Skip to content

Commit 63d1a34

Browse files
committed
pybricks.tools: Fix cancellation when not active.
This would shedule cancellation even when already completed. This flagged the awaitable not ready for recycling, so would cause allocation when this isn't needed.
1 parent 67c2e3f commit 63d1a34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pybricks/tools/pb_type_async.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
/**
1515
* Cancels the iterable so it will stop awaiting.
1616
*
17-
* This will not call close(). Safe to call even if iter is NULL.
17+
* This will not call close(). Safe to call even if iter is NULL or if it is
18+
* already complete.
1819
*
1920
* @param [in] iter The awaitable object.
2021
*/
2122
void pb_type_async_schedule_cancel(pb_type_async_t *iter) {
22-
if (!iter) {
23+
if (!iter || iter->parent_obj == MP_OBJ_NULL) {
24+
// Don't schedule if already complete.
2325
return;
2426
}
2527
// Don't set it to MP_OBJ_NULL right away, or the calling code wouldn't

0 commit comments

Comments
 (0)