diff --git a/lib/Internal/EmitSource.php b/lib/Internal/EmitSource.php index 0029d97..f924136 100644 --- a/lib/Internal/EmitSource.php +++ b/lib/Internal/EmitSource.php @@ -226,6 +226,14 @@ final class EmitSource return $this->completed; } + /** + * @return bool True if the stream was disposed. + */ + public function isDisposed(): bool + { + return $this->disposed; + } + /** * Completes the stream. ** diff --git a/lib/StreamSource.php b/lib/StreamSource.php index e2ca679..a0fc62f 100644 --- a/lib/StreamSource.php +++ b/lib/StreamSource.php @@ -56,6 +56,14 @@ final class StreamSource return $this->source->isComplete(); } + /** + * @return bool True if the stream has been disposed. + */ + public function isDisposed(): bool + { + return $this->source->isDisposed(); + } + /** * Completes the stream. * diff --git a/test/StreamSourceTest.php b/test/StreamSourceTest.php index 7e72635..136942b 100644 --- a/test/StreamSourceTest.php +++ b/test/StreamSourceTest.php @@ -213,6 +213,7 @@ class StreamSourceTest extends AsyncTestCase $stream = $this->source->stream(); $promise = $this->source->emit(1); $stream->dispose(); + $this->assertTrue($this->source->isDisposed()); $this->assertNull(yield $promise); yield $this->source->emit(1); } @@ -226,6 +227,7 @@ class StreamSourceTest extends AsyncTestCase $stream = $this->source->stream(); $promise = $this->source->emit(1); unset($stream); + $this->assertTrue($this->source->isDisposed()); $this->assertNull(yield $promise); yield $this->source->emit(1); }