Skip to content

Commit e104db0

Browse files
committed
Use generator to return notifications
1 parent bdd62b9 commit e104db0

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/Server/NotificationPublisher.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ public function enqueue(string $notificationType): void
4545
}
4646

4747
/**
48-
* @return iterable<Notification>
48+
* @return \Generator<int, Notification, void, void>
4949
*/
5050
public function flush(): iterable
5151
{
52-
if (!$this->queue) {
53-
return [];
54-
}
55-
5652
$out = $this->queue;
5753
$this->queue = [];
5854

59-
return $out;
55+
yield from $out;
6056
}
6157
}

tests/Server/NotificationPublisherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public function testEnqueue(): void
3838
$notificationPublisher->enqueue($notificationType);
3939
}
4040

41-
$flushedNotifications = $notificationPublisher->flush();
41+
$flushedNotifications = iterator_to_array($notificationPublisher->flush());
4242

4343
$this->assertCount(\count($expectedNotifications), $flushedNotifications);
4444

4545
foreach ($flushedNotifications as $index => $notification) {
4646
$this->assertInstanceOf($expectedNotifications[$index], $notification);
4747
}
4848

49-
$this->assertEmpty($notificationPublisher->flush());
49+
$this->assertEmpty(iterator_to_array($notificationPublisher->flush()));
5050
}
5151
}

0 commit comments

Comments
 (0)