Skip to content

Commit dc474a7

Browse files
committed
#31: + Added support for waiting on identical objects, even if they have different keys.
1 parent bdb44a7 commit dc474a7

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

tests/await/071-awaitAll_with_cancellation_simultaneously.phpt

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,14 @@ $coroutine2 = spawn(function() {
1616
return "second";
1717
});
1818

19-
$result = awaitAll([$coroutine1, $coroutine2], $coroutine2);
20-
var_dump($result);
19+
try {
20+
$result = awaitAll([$coroutine1, $coroutine2], $coroutine2);
21+
var_dump($result);
22+
} catch (\Async\CancellationException $e) {
23+
}
2124

2225
echo "end\n";
2326
?>
2427
--EXPECTF--
2528
start
26-
array(2) {
27-
[0]=>
28-
array(2) {
29-
[0]=>
30-
string(5) "first"
31-
[2]=>
32-
string(5) "third"
33-
}
34-
[1]=>
35-
array(1) {
36-
[1]=>
37-
object(RuntimeException)#%d (7) {
38-
["message":protected]=>
39-
string(14) "test exception"
40-
["string":"Exception":private]=>
41-
string(0) ""
42-
["code":protected]=>
43-
int(0)
44-
["file":protected]=>
45-
string(%d) "%s"
46-
["line":protected]=>
47-
int(%d)
48-
["trace":"Exception":private]=>
49-
array(%d) {
50-
%a
51-
}
52-
["previous":"Exception":private]=>
53-
NULL
54-
}
55-
}
56-
}
5729
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
awaitAll() - Attempt to wait for two identical objects.
3+
--FILE--
4+
<?php
5+
6+
use function Async\spawn;
7+
use function Async\awaitAll;
8+
9+
echo "start\n";
10+
11+
$coroutine1 = spawn(function() {
12+
return "first";
13+
});
14+
15+
$coroutine2 = spawn(function() {
16+
return "second";
17+
});
18+
19+
$result = awaitAll([$coroutine1, $coroutine2, $coroutine1, $coroutine2]);
20+
var_dump($result);
21+
22+
echo "end\n";
23+
?>
24+
--EXPECTF--
25+
start
26+
array(2) {
27+
[0]=>
28+
array(4) {
29+
[0]=>
30+
string(5) "first"
31+
[1]=>
32+
string(6) "second"
33+
[2]=>
34+
string(5) "first"
35+
[3]=>
36+
string(6) "second"
37+
}
38+
[1]=>
39+
array(0) {
40+
}
41+
}
42+
end

0 commit comments

Comments
 (0)