1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00
amp/lib/Stream.php
Aaron Piotrowski 4935dddc84 Refactor Streams
Dropped original Stream interface in favor of the Iterator interface. Eliminates subscriber timing issues and simplifies Stream usage.
2017-05-02 07:04:10 +02:00

30 lines
968 B
PHP

<?php
namespace Amp;
/**
* Defines an asynchronous stream that is designed to be used within a coroutine.
*/
interface Stream {
/**
* Succeeds with true if an emitted value is available by calling getCurrent() or false if the stream has resolved.
* If the stream fails, the returned promise will fail with the same exception.
*
* @return \Amp\Promise<bool>
*
* @throws \Error If the prior promise returned from this method has not resolved.
* @throws \Throwable The exception used to fail the stream.
*/
public function advance(): Promise;
/**
* Gets the last emitted value or throws an exception if the stream has completed.
*
* @return mixed Value emitted from the stream.
*
* @throws \Error If the stream has resolved or advance() was not called before calling this method.
* @throws \Throwable The exception used to fail the stream.
*/
public function getCurrent();
}