2020-05-13 10:15:21 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A stream is an asynchronous set of ordered values.
|
|
|
|
*
|
|
|
|
* @template-covariant TValue
|
|
|
|
*/
|
|
|
|
interface Stream
|
|
|
|
{
|
|
|
|
/**
|
2020-07-16 13:50:38 -05:00
|
|
|
* Succeeds with the emitted value if the stream has emitted a value or null if the stream has completed.
|
2020-05-21 10:11:22 -05:00
|
|
|
* If the stream fails, the returned promise will fail with the same exception.
|
2020-05-13 10:15:21 -05:00
|
|
|
*
|
2020-05-21 10:11:22 -05:00
|
|
|
* @return Promise<mixed|null> Resolves with null if the stream has completed.
|
2020-05-16 10:39:34 -05:00
|
|
|
*
|
2020-05-21 10:11:22 -05:00
|
|
|
* @psalm-return Promise<TValue|null>
|
2020-05-13 10:15:21 -05:00
|
|
|
*
|
|
|
|
* @throws \Throwable The exception used to fail the stream.
|
|
|
|
*/
|
|
|
|
public function continue(): Promise;
|
2020-05-13 14:59:31 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disposes of the stream, indicating the consumer is no longer interested in the stream output.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function dispose();
|
2020-07-30 14:33:39 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a callback to be invoked *only* if the stream is disposed before being completed or failed.
|
|
|
|
*
|
|
|
|
* @param callable():void $onDisposal
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function onDisposal(callable $onDisposal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a callback to be invoked when the stream is completed or failed. If the stream is failed, the exception
|
|
|
|
* used to fail the stream is given as the first argument to the callback. Null is given as the first argument if
|
|
|
|
* the stream is completed.
|
|
|
|
*
|
|
|
|
* @param callable(?\Throwable):void $onCompletion
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function onCompletion(callable $onCompletion);
|
2020-05-13 10:15:21 -05:00
|
|
|
}
|