Skip to content

Commit c365221

Browse files
committed
#53: * fix await iterator logic
1 parent b4e3886 commit c365221

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

async_API.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ static void await_iterator_dispose(async_await_iterator_t *iterator, async_itera
610610
iterator->zend_iterator = NULL;
611611

612612
// When the iterator has finished, it’s now possible to specify the exact number of elements since it’s known.
613-
iterator->await_context->total = iterator->await_context->futures_count;
613+
iterator->await_context->total = iterator->await_context->futures_count +
614+
iterator->await_context->resolved_count;
614615

615616
// Scenario: the iterator has already finished, and there’s nothing left to await.
616617
// In that case, the coroutine needs to be terminated.

scheduler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,8 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
12891289
bool was_executed = false;
12901290
switch_status status = COROUTINE_NOT_EXISTS;
12911291

1292-
const circular_buffer_t * coroutine_queue = &ASYNC_G(coroutine_queue);
1292+
const circular_buffer_t *coroutine_queue = &ASYNC_G(coroutine_queue);
1293+
const circular_buffer_t *resumed_coroutines = &ASYNC_G(resumed_coroutines);
12931294

12941295
do {
12951296

@@ -1305,7 +1306,7 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
13051306
has_next_coroutine = circular_buffer_count(coroutine_queue) > 0;
13061307
has_handles = ZEND_ASYNC_REACTOR_EXECUTE(has_next_coroutine);
13071308

1308-
if (circular_buffer_is_not_empty(&ASYNC_G(resumed_coroutines))) {
1309+
if (circular_buffer_is_not_empty(resumed_coroutines)) {
13091310
process_resumed_coroutines();
13101311
}
13111312

tests/await/008-awaitFirstSuccess_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ echo "start\n";
1111

1212
$coroutines = [
1313
spawn(function() {
14-
suspend();
14+
//suspend();
1515
throw new RuntimeException("first error");
1616
}),
1717
spawn(function() {

tests/await/016-awaitAnyOf_basic.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ $coroutines = [
1414
return "first";
1515
}),
1616
spawn(function() {
17-
suspend();
1817
throw new RuntimeException("test exception");
1918
}),
2019
spawn(function() {

tests/await/043-awaitAnyOfOrFail_associative_array.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $coroutines = [
3030

3131
echo "start\n";
3232

33-
$results = awaitAnyOfOrFail(2, $coroutines);
33+
$results = awaitAnyOfOrFail(3, $coroutines);
3434

3535
echo "Keys preserved: " . (count(array_intersect(array_keys($results), ['slow', 'fast', 'medium', 'very_slow'])) == count($results) ? "YES" : "NO") . "\n";
3636

0 commit comments

Comments
 (0)