Skip to content

Commit 9c094e3

Browse files
authored
Merge pull request #29 from true-async/22-revise-the-awaitall-methods-and-others-according-to-the-principle-of-least-astonishment
#22: + Fix test failures after API function renaming
2 parents c7a6f2a + 32d358b commit 9c094e3

File tree

58 files changed

+190
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+190
-182
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Fixed the `spawnWith()` function for interaction with the `ScopeProvider` and `SpawnStrategy` interface
3333

3434
### Changed
35+
- **Breaking Change: Function Renaming** - Major API reorganization for better consistency:
36+
- `awaitAllFailFirst()``awaitAllOrFail()`
37+
- `awaitAllWithErrors()``awaitAll()`
38+
- `awaitAnyOfFailFirst()``awaitAnyOfOrFail()`
39+
- `awaitAnyOfWithErrors()``awaitAnyOf()`
40+
- **Breaking Change: `awaitAll()` Return Format** - New `awaitAll()` (formerly `awaitAllWithErrors()`) now returns `[results, exceptions]` tuple:
41+
- First element `[0]` contains array of successful results
42+
- Second element `[1]` contains array of exceptions from failed coroutines
43+
- **Migration**: Update from `$results = awaitAll($coroutines)` to `[$results, $exceptions] = awaitAll($coroutines)`
3544
- **LibUV requirement increased to ≥ 1.44.0** - Requires libuv version 1.44.0 or later to ensure proper UV_RUN_ONCE behavior and prevent busy loop issues that could cause high CPU usage
3645
- **Async Iterator API**:
3746
- Proper handling of `REWIND`/`NEXT` states in a concurrent environment.
3847
The iterator code now stops iteration in
3948
coroutines if the iterator is in the process of changing its position.
4049
- Added functionality for proper handling of exceptions from `Zend iterators` (`\Iterator` and `generators`).
41-
An exception that occurs in the iterator can now be handled by the iterators owner.
50+
An exception that occurs in the iterator can now be handled by the iterator's owner.
4251

4352

4453
## [0.2.0] - 2025-07-01

async.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ PHP_FUNCTION(Async_await)
293293
zend_async_waker_destroy(coroutine);
294294
}
295295

296-
PHP_FUNCTION(Async_awaitAny)
296+
PHP_FUNCTION(Async_awaitAnyOrFail)
297297
{
298298
zval * futures;
299299
zend_object * cancellation = NULL;
@@ -397,7 +397,7 @@ PHP_FUNCTION(Async_awaitFirstSuccess)
397397
RETURN_ARR(return_array);
398398
}
399399

400-
PHP_FUNCTION(Async_awaitAll)
400+
PHP_FUNCTION(Async_awaitAllOrFail)
401401
{
402402
zval * futures;
403403
zend_object * cancellation = NULL;
@@ -437,7 +437,7 @@ PHP_FUNCTION(Async_awaitAll)
437437
RETURN_ARR(results);
438438
}
439439

440-
PHP_FUNCTION(Async_awaitAllWithErrors)
440+
PHP_FUNCTION(Async_awaitAll)
441441
{
442442
zval * futures;
443443
zend_object * cancellation = NULL;
@@ -488,7 +488,7 @@ PHP_FUNCTION(Async_awaitAllWithErrors)
488488
RETURN_ARR(return_array);
489489
}
490490

491-
PHP_FUNCTION(Async_awaitAnyOf)
491+
PHP_FUNCTION(Async_awaitAnyOfOrFail)
492492
{
493493
zval * futures;
494494
zend_object * cancellation = NULL;
@@ -532,7 +532,7 @@ PHP_FUNCTION(Async_awaitAnyOf)
532532
RETURN_ARR(results);
533533
}
534534

535-
PHP_FUNCTION(Async_awaitAnyOfWithErrors)
535+
PHP_FUNCTION(Async_awaitAnyOf)
536536
{
537537
zval * futures;
538538
zend_object * cancellation = NULL;

async.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ function protect(\Closure $closure): mixed {}
3737

3838
function await(Awaitable $awaitable, ?Awaitable $cancellation = null): mixed {}
3939

40-
function awaitAny(iterable $triggers, ?Awaitable $cancellation = null): mixed {}
40+
function awaitAnyOrFail(iterable $triggers, ?Awaitable $cancellation = null): mixed {}
4141

4242
function awaitFirstSuccess(iterable $triggers, ?Awaitable $cancellation = null): mixed {}
4343

44-
function awaitAll(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
44+
function awaitAllOrFail(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
4545

46-
function awaitAllWithErrors(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true, bool $fillNull = false): array {}
46+
function awaitAll(iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true, bool $fillNull = false): array {}
4747

48-
function awaitAnyOf(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
48+
function awaitAnyOfOrFail(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true): array {}
4949

50-
function awaitAnyOfWithErrors(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder= true, bool $fillNull = false): array {}
50+
function awaitAnyOf(int $count, iterable $triggers, ?Awaitable $cancellation = null, bool $preserveKeyOrder = true, bool $fillNull = false): array {}
5151

5252
function delay(int $ms): void {}
5353

async_arginfo.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_await, 0, 1, IS_MIXED, 0)
2424
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
2525
ZEND_END_ARG_INFO()
2626

27-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAny, 0, 1, IS_MIXED, 0)
27+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOrFail, 0, 1, IS_MIXED, 0)
2828
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
2929
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
3030
ZEND_END_ARG_INFO()
3131

32-
#define arginfo_Async_awaitFirstSuccess arginfo_Async_awaitAny
32+
#define arginfo_Async_awaitFirstSuccess arginfo_Async_awaitAnyOrFail
3333

34-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAll, 0, 1, IS_ARRAY, 0)
34+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAllOrFail, 0, 1, IS_ARRAY, 0)
3535
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
3636
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
3737
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
3838
ZEND_END_ARG_INFO()
3939

40-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAllWithErrors, 0, 1, IS_ARRAY, 0)
40+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAll, 0, 1, IS_ARRAY, 0)
4141
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
4242
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
4343
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
4444
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fillNull, _IS_BOOL, 0, "false")
4545
ZEND_END_ARG_INFO()
4646

47-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOf, 0, 2, IS_ARRAY, 0)
47+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOfOrFail, 0, 2, IS_ARRAY, 0)
4848
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
4949
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
5050
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
5151
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preserveKeyOrder, _IS_BOOL, 0, "true")
5252
ZEND_END_ARG_INFO()
5353

54-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOfWithErrors, 0, 2, IS_ARRAY, 0)
54+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Async_awaitAnyOf, 0, 2, IS_ARRAY, 0)
5555
ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0)
5656
ZEND_ARG_OBJ_TYPE_MASK(0, triggers, Traversable, MAY_BE_ARRAY, NULL)
5757
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, cancellation, Async\\Awaitable, 1, "null")
@@ -92,12 +92,12 @@ ZEND_FUNCTION(Async_spawnWith);
9292
ZEND_FUNCTION(Async_suspend);
9393
ZEND_FUNCTION(Async_protect);
9494
ZEND_FUNCTION(Async_await);
95-
ZEND_FUNCTION(Async_awaitAny);
95+
ZEND_FUNCTION(Async_awaitAnyOrFail);
9696
ZEND_FUNCTION(Async_awaitFirstSuccess);
97+
ZEND_FUNCTION(Async_awaitAllOrFail);
9798
ZEND_FUNCTION(Async_awaitAll);
98-
ZEND_FUNCTION(Async_awaitAllWithErrors);
99+
ZEND_FUNCTION(Async_awaitAnyOfOrFail);
99100
ZEND_FUNCTION(Async_awaitAnyOf);
100-
ZEND_FUNCTION(Async_awaitAnyOfWithErrors);
101101
ZEND_FUNCTION(Async_delay);
102102
ZEND_FUNCTION(Async_timeout);
103103
ZEND_FUNCTION(Async_currentContext);
@@ -114,12 +114,12 @@ static const zend_function_entry ext_functions[] = {
114114
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "suspend"), zif_Async_suspend, arginfo_Async_suspend, 0, NULL, NULL)
115115
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "protect"), zif_Async_protect, arginfo_Async_protect, 0, NULL, NULL)
116116
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "await"), zif_Async_await, arginfo_Async_await, 0, NULL, NULL)
117-
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAny"), zif_Async_awaitAny, arginfo_Async_awaitAny, 0, NULL, NULL)
117+
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOrFail"), zif_Async_awaitAnyOrFail, arginfo_Async_awaitAnyOrFail, 0, NULL, NULL)
118118
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitFirstSuccess"), zif_Async_awaitFirstSuccess, arginfo_Async_awaitFirstSuccess, 0, NULL, NULL)
119+
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAllOrFail"), zif_Async_awaitAllOrFail, arginfo_Async_awaitAllOrFail, 0, NULL, NULL)
119120
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAll"), zif_Async_awaitAll, arginfo_Async_awaitAll, 0, NULL, NULL)
120-
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAllWithErrors"), zif_Async_awaitAllWithErrors, arginfo_Async_awaitAllWithErrors, 0, NULL, NULL)
121+
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOfOrFail"), zif_Async_awaitAnyOfOrFail, arginfo_Async_awaitAnyOfOrFail, 0, NULL, NULL)
121122
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOf"), zif_Async_awaitAnyOf, arginfo_Async_awaitAnyOf, 0, NULL, NULL)
122-
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "awaitAnyOfWithErrors"), zif_Async_awaitAnyOfWithErrors, arginfo_Async_awaitAnyOfWithErrors, 0, NULL, NULL)
123123
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "delay"), zif_Async_delay, arginfo_Async_delay, 0, NULL, NULL)
124124
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "timeout"), zif_Async_timeout, arginfo_Async_timeout, 0, NULL, NULL)
125125
ZEND_RAW_FENTRY(ZEND_NS_NAME("Async", "currentContext"), zif_Async_currentContext, arginfo_Async_currentContext, 0, NULL, NULL)

tests/await/005-awaitAny_basic.phpt renamed to tests/await/005-awaitAnyOrFail_basic.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
awaitAny() - basic usage with multiple coroutines
2+
awaitAnyOrFail() - basic usage with multiple coroutines
33
--FILE--
44
<?php
55

66
use function Async\spawn;
7-
use function Async\awaitAny;
7+
use function Async\awaitAnyOrFail;
88
use function Async\delay;
99
use function Async\suspend;
1010

@@ -24,7 +24,7 @@ $coroutines = [
2424
}),
2525
];
2626

27-
$result = awaitAny($coroutines);
27+
$result = awaitAnyOrFail($coroutines);
2828
echo "first completed: $result\n";
2929

3030
echo "end\n";

tests/await/006-awaitAny_empty.phpt renamed to tests/await/006-awaitAnyOrFail_empty.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
--TEST--
2-
awaitAny() - empty iterable
2+
awaitAnyOrFail() - empty iterable
33
--FILE--
44
<?php
55

6-
use function Async\awaitAny;
6+
use function Async\awaitAnyOrFail;
77

88
echo "start\n";
99

10-
$result = awaitAny([]);
10+
$result = awaitAnyOrFail([]);
1111

1212
$resultCheck = $result === null ? "OK" : "FALSE: " . var_export($result, true);
1313
echo "Result is null: $resultCheck\n";

tests/await/007-awaitAny_exception.phpt renamed to tests/await/007-awaitAnyOrFail_exception.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
awaitAny() - coroutine throws exception
2+
awaitAnyOrFail() - coroutine throws exception
33
--FILE--
44
<?php
55

66
use function Async\spawn;
7-
use function Async\awaitAny;
7+
use function Async\awaitAnyOrFail;
88
use function Async\suspend;
99

1010
echo "start\n";
@@ -20,7 +20,7 @@ $coroutines = [
2020
];
2121

2222
try {
23-
$result = awaitAny($coroutines);
23+
$result = awaitAnyOrFail($coroutines);
2424
echo "result: $result\n";
2525
} catch (RuntimeException $e) {
2626
echo "caught exception: " . $e->getMessage() . "\n";

tests/await/010-awaitAll_basic.phpt renamed to tests/await/010-awaitAllOrFail_basic.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
awaitAll() - basic usage with multiple coroutines
2+
awaitAllOrFail() - basic usage with multiple coroutines
33
--FILE--
44
<?php
55

66
use function Async\spawn;
7-
use function Async\awaitAll;
7+
use function Async\awaitAllOrFail;
88

99
echo "start\n";
1010

@@ -20,7 +20,7 @@ $coroutines = [
2020
}),
2121
];
2222

23-
$results = awaitAll($coroutines);
23+
$results = awaitAllOrFail($coroutines);
2424
var_dump($results);
2525

2626
echo "end\n";

tests/await/011-awaitAll_exception.phpt renamed to tests/await/011-awaitAllOrFail_exception.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
awaitAll() - one coroutine throws exception
2+
awaitAllOrFail() - one coroutine throws exception
33
--FILE--
44
<?php
55

66
use function Async\spawn;
7-
use function Async\awaitAll;
7+
use function Async\awaitAllOrFail;
88

99
echo "start\n";
1010

@@ -21,7 +21,7 @@ $coroutines = [
2121
];
2222

2323
try {
24-
$results = awaitAll($coroutines);
24+
$results = awaitAllOrFail($coroutines);
2525
var_dump($results);
2626
} catch (RuntimeException $e) {
2727
echo "caught exception: " . $e->getMessage() . "\n";

tests/await/012-awaitAllWithErrors_basic.phpt renamed to tests/await/012-awaitAll_basic.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
--TEST--
2-
awaitAllWithErrors() - basic usage with mixed success and error
2+
awaitAll() - basic usage with mixed success and error
33
--FILE--
44
<?php
55

66
use function Async\spawn;
7-
use function Async\awaitAllWithErrors;
7+
use function Async\awaitAll;
88

99
echo "start\n";
1010

@@ -20,7 +20,7 @@ $coroutines = [
2020
}),
2121
];
2222

23-
$result = awaitAllWithErrors($coroutines);
23+
$result = awaitAll($coroutines);
2424
var_dump($result);
2525

2626
echo "end\n";

0 commit comments

Comments
 (0)