Skip to content

Commit

Permalink
Replace more occurrences of stream
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Apr 28, 2017
1 parent f592bcc commit 878a9a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/Internal/Producer.php
Expand Up @@ -68,7 +68,7 @@ public function advance(): Promise {
*/
public function getCurrent() {
if (empty($this->values) && $this->complete) {
throw new \Error("The stream has completed");
throw new \Error("The iterator has completed");
}

if (!\array_key_exists($this->position, $this->values)) {
Expand All @@ -79,18 +79,18 @@ public function getCurrent() {
}

/**
* Emits a value from the stream. The returned promise is resolved with the emitted value once all listeners
* Emits a value from the iterator. The returned promise is resolved with the emitted value once all listeners
* have been invoked.
*
* @param mixed $value
*
* @return \Amp\Promise
*
* @throws \Error If the stream has completed.
* @throws \Error If the iterator has completed.
*/
private function emit($value): Promise {
if ($this->complete) {
throw new \Error("Streams cannot emit values after calling complete");
throw new \Error("Iterators cannot emit values after calling complete");
}

if ($value instanceof ReactPromise) {
Expand All @@ -102,7 +102,7 @@ private function emit($value): Promise {
$value->onResolve(function ($e, $v) use ($deferred) {
if ($this->complete) {
$deferred->fail(
new \Error("The stream was completed before the promise result could be emitted")
new \Error("The iterator was completed before the promise result could be emitted")
);
return;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ private function emit($value): Promise {
/**
* Completes the iterator.
*
* @throws \Error If the stream has already been completed.
* @throws \Error If the iterator has already been completed.
*/
private function complete() {
if ($this->complete) {
Expand Down
6 changes: 3 additions & 3 deletions test/ProducerTraitTest.php
Expand Up @@ -134,7 +134,7 @@ public function testEmitPendingPromiseThenNonPromise() {
/**
* @depends testEmit
* @expectedException \Error
* @expectedExceptionMessage Streams cannot emit values after calling complete
* @expectedExceptionMessage Iterators cannot emit values after calling complete
*/
public function testEmitAfterComplete() {
$this->producer->complete();
Expand All @@ -144,7 +144,7 @@ public function testEmitAfterComplete() {
/**
* @depends testEmit
* @expectedException \Error
* @expectedExceptionMessage The stream was completed before the promise result could be emitted
* @expectedExceptionMessage The iterator was completed before the promise result could be emitted
*/
public function testEmitPendingPromiseThenComplete() {
$invoked = false;
Expand All @@ -167,7 +167,7 @@ public function testEmitPendingPromiseThenComplete() {
/**
* @depends testEmit
* @expectedException \Error
* @expectedExceptionMessage The stream was completed before the promise result could be emitted
* @expectedExceptionMessage The iterator was completed before the promise result could be emitted

This comment has been minimized.

Copy link
@kelunik

kelunik Apr 28, 2017

Member

This shouldn't fail IMO. Complete should just not allow further emit calls, but the already done emits should complete normally.

This comment has been minimized.

Copy link
@trowski

trowski Apr 28, 2017

Author Member

Just to be clear, this is only the promise returned from emit() that is failing.

Changing this behavior this would require greater complexity in the emitter, waiting for any prior emitted promise to resolve before emitting again or completing. If code creating an emitter cares about this order, it can just wait for the promise to either resolve before emitting the value or wait for the promise returned from emit() to resolve before emitting again.

*/
public function testEmitPendingPromiseThenFail() {
$invoked = false;
Expand Down

0 comments on commit 878a9a6

Please sign in to comment.