1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Stream.php

30 lines
968 B
PHP
Raw Normal View History

<?php
2016-08-15 23:46:26 -05:00
2016-05-24 11:47:14 -05:00
namespace Amp;
2016-06-01 11:37:12 -05:00
/**
* Defines an asynchronous stream that is designed to be used within a coroutine.
2016-06-01 11:37:12 -05:00
*/
interface Stream {
2016-05-24 11:47:14 -05:00
/**
* 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.
2016-05-26 18:20:05 -05:00
*
* @return \Amp\Promise<bool>
2016-05-27 15:44:01 -05:00
*
* @throws \Error If the prior promise returned from this method has not resolved.
* @throws \Throwable The exception used to fail the stream.
2016-05-24 11:47:14 -05:00
*/
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();
2016-05-24 11:47:14 -05:00
}