PHP Class Amp\Observer

Example: $observer = new Observer($observable); // $observable is an instance of \Amp\Observable while (yield $observer->next()) { $emitted = $observer->getCurrent(); } $result = $observer->getResult();
Show file Open project: amphp/amp

Public Methods

Method Description
__construct ( amp\Observable $observable )
__destruct ( ) Marks the observer as resolved to relieve back-pressure on the observable.
drain ( ) : array Returns an array of values that were not consumed by the Observer before the Observable completed.
getCurrent ( ) : mixed Gets the last emitted value or throws an exception if the observable has completed.
getResult ( ) : mixed Gets the result of the observable or throws the failure reason. Also throws an exception if the observable has not completed.
next ( ) : Interop\Async\Promise Succeeds with true if an emitted value is available by calling getCurrent() or false if the observable has resolved. If the observable fails, the returned promise will fail with the same exception.
observe ( ) : amp\Observable

Method Details

__construct() public method

public __construct ( amp\Observable $observable )
$observable amp\Observable

__destruct() public method

Marks the observer as resolved to relieve back-pressure on the observable.
public __destruct ( )

drain() public method

Returns an array of values that were not consumed by the Observer before the Observable completed.
public drain ( ) : array
return array Unconsumed emitted values.

getCurrent() public method

Gets the last emitted value or throws an exception if the observable has completed.
public getCurrent ( ) : mixed
return mixed Value emitted from observable.

getResult() public method

Gets the result of the observable or throws the failure reason. Also throws an exception if the observable has not completed.
public getResult ( ) : mixed
return mixed Final return value of the observable.

next() public method

Succeeds with true if an emitted value is available by calling getCurrent() or false if the observable has resolved. If the observable fails, the returned promise will fail with the same exception.
public next ( ) : Interop\Async\Promise
return Interop\Async\Promise

observe() public method

public observe ( ) : amp\Observable
return amp\Observable The observable being observed.