docs/class-GuzzleHttp.Promise.Coroutine.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Class GuzzleHttp\Promise\Coroutine | ξ ^ω^)ξ Baguette PHP Mastodon API Client / SDK</title>
<link rel="stylesheet" href="resources/style.css?c2f33731c1948fbed7c333554678bfa68d4817da">
</head>
<body>
<div id="left">
<div id="menu">
<a href="index.html" title="Overview"><span>Overview</span></a>
<div id="groups">
<h3>Namespaces</h3>
<ul>
<li>
<a href="namespace-Baguette.html">
Baguette<span></span>
</a>
<ul>
<li>
<a href="namespace-Baguette.Mastodon.html">
Mastodon<span></span>
</a>
<ul>
<li class="main">
<a href="namespace-Baguette.Mastodon.Config.html">
Config </a>
</li>
<li class="main">
<a href="namespace-Baguette.Mastodon.Entity.html">
Entity </a>
</li>
<li class="main">
<a href="namespace-Baguette.Mastodon.Grant.html">
Grant </a>
</li>
<li class="main">
<a href="namespace-Baguette.Mastodon.Service.html">
Service </a>
</li>
</ul></li></ul></li>
<li class="active">
<a href="namespace-GuzzleHttp.html">
GuzzleHttp<span></span>
</a>
<ul>
<li>
<a href="namespace-GuzzleHttp.Cookie.html">
Cookie </a>
</li>
<li>
<a href="namespace-GuzzleHttp.Exception.html">
Exception </a>
</li>
<li>
<a href="namespace-GuzzleHttp.Handler.html">
Handler </a>
</li>
<li class="active">
<a href="namespace-GuzzleHttp.Promise.html">
Promise </a>
</li>
</ul></li>
<li>
<a href="namespace-Psr.html">
Psr<span></span>
</a>
<ul>
<li>
<a href="namespace-Psr.Http.html">
Http<span></span>
</a>
<ul>
<li>
<a href="namespace-Psr.Http.Message.html">
Message </a>
</li>
</ul></li></ul></li>
<li>
<a href="namespace-Teto.html">
Teto<span></span>
</a>
<ul>
<li>
<a href="namespace-Teto.Object.html">
Object </a>
</li>
</ul></li>
</ul>
</div>
<hr>
<div id="elements">
<h3>Classes</h3>
<ul>
<li class="active"><a href="class-GuzzleHttp.Promise.Coroutine.html">Coroutine</a></li>
<li><a href="class-GuzzleHttp.Promise.EachPromise.html">EachPromise</a></li>
<li><a href="class-GuzzleHttp.Promise.FulfilledPromise.html">FulfilledPromise</a></li>
<li><a href="class-GuzzleHttp.Promise.Promise.html">Promise</a></li>
<li><a href="class-GuzzleHttp.Promise.RejectedPromise.html">RejectedPromise</a></li>
<li><a href="class-GuzzleHttp.Promise.TaskQueue.html">TaskQueue</a></li>
</ul>
<h3>Interfaces</h3>
<ul>
<li><a href="class-GuzzleHttp.Promise.PromiseInterface.html">PromiseInterface</a></li>
<li><a href="class-GuzzleHttp.Promise.PromisorInterface.html">PromisorInterface</a></li>
<li><a href="class-GuzzleHttp.Promise.TaskQueueInterface.html">TaskQueueInterface</a></li>
</ul>
<h3>Exceptions</h3>
<ul>
<li><a href="class-GuzzleHttp.Promise.AggregateException.html">AggregateException</a></li>
<li><a href="class-GuzzleHttp.Promise.CancellationException.html">CancellationException</a></li>
<li><a href="class-GuzzleHttp.Promise.RejectionException.html">RejectionException</a></li>
</ul>
<h3>Functions</h3>
<ul>
<li><a href="function-GuzzleHttp.Promise.all.html">all</a></li>
<li><a href="function-GuzzleHttp.Promise.any.html">any</a></li>
<li><a href="function-GuzzleHttp.Promise.coroutine.html">coroutine</a></li>
<li><a href="function-GuzzleHttp.Promise.each.html">each</a></li>
<li><a href="function-GuzzleHttp.Promise.each_limit.html">each_limit</a></li>
<li><a href="function-GuzzleHttp.Promise.each_limit_all.html">each_limit_all</a></li>
<li><a href="function-GuzzleHttp.Promise.exception_for.html">exception_for</a></li>
<li><a href="function-GuzzleHttp.Promise.inspect.html">inspect</a></li>
<li><a href="function-GuzzleHttp.Promise.inspect_all.html">inspect_all</a></li>
<li><a href="function-GuzzleHttp.Promise.is_fulfilled.html">is_fulfilled</a></li>
<li><a href="function-GuzzleHttp.Promise.is_rejected.html">is_rejected</a></li>
<li><a href="function-GuzzleHttp.Promise.is_settled.html">is_settled</a></li>
<li><a href="function-GuzzleHttp.Promise.iter_for.html">iter_for</a></li>
<li><a href="function-GuzzleHttp.Promise.promise_for.html">promise_for</a></li>
<li><a href="function-GuzzleHttp.Promise.queue.html">queue</a></li>
<li><a href="function-GuzzleHttp.Promise.rejection_for.html">rejection_for</a></li>
<li><a href="function-GuzzleHttp.Promise.settle.html">settle</a></li>
<li><a href="function-GuzzleHttp.Promise.some.html">some</a></li>
<li><a href="function-GuzzleHttp.Promise.task.html">task</a></li>
<li><a href="function-GuzzleHttp.Promise.unwrap.html">unwrap</a></li>
</ul>
</div>
</div>
</div>
<div id="splitter"></div>
<div id="right">
<div id="rightInner">
<form id="search">
<input type="hidden" name="cx" value="">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" name="q" class="text" placeholder="Search">
</form>
<div id="navigation">
<ul>
<li>
<a href="index.html" title="Overview"><span>Overview</span></a>
</li>
<li>
<a href="namespace-GuzzleHttp.Promise.html" title="Summary of GuzzleHttp\Promise"><span>Namespace</span></a>
</li>
<li class="active">
<span>Class</span> </li>
</ul>
<ul>
</ul>
<ul>
</ul>
</div>
<div id="content" class="class">
<h1>Class Coroutine</h1>
<div class="description">
<p>Creates a promise that is resolved using a generator that yields values or
promises (somewhat similar to C#'s async keyword).</p>
<p>When called, the coroutine function will start an instance of the generator
and returns a promise that is fulfilled with its final yielded value.</p>
<p>Control is returned back to the generator when the yielded promise settles.
This can lead to less verbose code when doing lots of sequential async calls
with minimal processing in between.
use GuzzleHttp\Promise;
function createPromise($value) { return new Promise\FulfilledPromise($value); }
$promise = Promise\coroutine(function () { $value = (yield createPromise('a')); try { $value = (yield createPromise($value . 'b')); } catch (\Exception $e) { // The promise was rejected. } yield $value . 'c'; });
// Outputs "abc" $promise->then(function ($v) { echo $v; });</p>
</div>
<dl class="tree">
<dd style="padding-left:0px">
<b><span>GuzzleHttp\Promise\Coroutine</span></b>
implements
<a href="class-GuzzleHttp.Promise.PromiseInterface.html"><span>GuzzleHttp\Promise\PromiseInterface</span></a>
</dd>
</dl>
<div class="info">
<b>Final</b><br>
<b>Namespace:</b> <a href="namespace-GuzzleHttp.html">GuzzleHttp</a>\<a href="namespace-GuzzleHttp.Promise.html">Promise</a><br>
<b>Link:</b>
<a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#generators">inspiration</a><br>
<b>Param:</b>
callable $generatorFn Generator function to wrap into a promise.<br>
<b>Return:</b>
<code><a href="class-GuzzleHttp.Promise.Promise.html">GuzzleHttp\Promise\Promise</a></code><br>
<b>Located at</b> <a href="source-class-GuzzleHttp.Promise.Coroutine.html#8-151" title="Go to source code">Coroutine.php</a>
<br>
</div>
<table class="summary methods" id="methods">
<caption>Methods summary</caption>
<tr data-order="__construct" id="___construct">
<td class="attributes"><code>
public
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#___construct">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#60-69" title="Go to source code">__construct</a>( <span>callable <var>$generatorFn</var></span> )</code>
<div class="description short">
</div>
<div class="description detailed hidden">
</div>
</div></td>
</tr>
<tr data-order="then" id="_then">
<td class="attributes"><code>
public
<code><a href="class-GuzzleHttp.Promise.PromiseInterface.html">GuzzleHttp\Promise\PromiseInterface</a></code>
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_then">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#71-76" title="Go to source code">then</a>( <span>callable <var>$onFulfilled</var> = <span class="php-keyword1">null</span></span>, <span>callable <var>$onRejected</var> = <span class="php-keyword1">null</span> </span> )</code>
<div class="description short">
<p>Appends fulfillment and rejection handlers to the promise, and returns
a new promise resolving to the return value of the called handler.</p>
</div>
<div class="description detailed hidden">
<p>Appends fulfillment and rejection handlers to the promise, and returns
a new promise resolving to the return value of the called handler.</p>
<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$onFulfilled</var></dt>
<dd>Invoked when the promise fulfills.</dd>
<dt><var>$onRejected</var></dt>
<dd>Invoked when the promise is rejected.</dd>
</dl></div>
<h4>Returns</h4>
<div class="list">
<code><a href="class-GuzzleHttp.Promise.PromiseInterface.html">GuzzleHttp\Promise\PromiseInterface</a></code>
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_then">GuzzleHttp\Promise\PromiseInterface::then()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="otherwise" id="_otherwise">
<td class="attributes"><code>
public
<code><a href="class-GuzzleHttp.Promise.PromiseInterface.html">GuzzleHttp\Promise\PromiseInterface</a></code>
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_otherwise">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#78-81" title="Go to source code">otherwise</a>( <span>callable <var>$onRejected</var></span> )</code>
<div class="description short">
<p>Appends a rejection handler callback to the promise, and returns a new
promise resolving to the return value of the callback if it is called,
or to its original fulfillment value if the promise is instead
fulfilled.</p>
</div>
<div class="description detailed hidden">
<p>Appends a rejection handler callback to the promise, and returns a new
promise resolving to the return value of the callback if it is called,
or to its original fulfillment value if the promise is instead
fulfilled.</p>
<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$onRejected</var></dt>
<dd>Invoked when the promise is rejected.</dd>
</dl></div>
<h4>Returns</h4>
<div class="list">
<code><a href="class-GuzzleHttp.Promise.PromiseInterface.html">GuzzleHttp\Promise\PromiseInterface</a></code>
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_otherwise">GuzzleHttp\Promise\PromiseInterface::otherwise()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="wait" id="_wait">
<td class="attributes"><code>
public
mixed
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_wait">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#83-86" title="Go to source code">wait</a>( <span>boolean <var>$unwrap</var> = <span class="php-keyword1">true</span></span> )</code>
<div class="description short">
<p>Waits until the promise completes if possible.</p>
</div>
<div class="description detailed hidden">
<p>Waits until the promise completes if possible.</p>
<p>Pass $unwrap as true to unwrap the result of the promise, either
returning the resolved value or throwing the rejected exception.</p>
<p>If the promise cannot be waited on, then the promise will be rejected.</p>
<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$unwrap</var></dt>
<dd></dd>
</dl></div>
<h4>Returns</h4>
<div class="list">
mixed
</div>
<h4>Throws</h4>
<div class="list">
LogicException<br><p>if the promise has no wait function or if the
promise does not settle after waiting.</p>
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_wait">GuzzleHttp\Promise\PromiseInterface::wait()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="getState" id="_getState">
<td class="attributes"><code>
public
string
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_getState">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#88-91" title="Go to source code">getState</a>( )</code>
<div class="description short">
<p>Get the state of the promise ("pending", "rejected", or "fulfilled").</p>
</div>
<div class="description detailed hidden">
<p>Get the state of the promise ("pending", "rejected", or "fulfilled").</p>
<p>The three states can be checked against the constants defined on
PromiseInterface: PENDING, FULFILLED, and REJECTED.</p>
<h4>Returns</h4>
<div class="list">
string
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_getState">GuzzleHttp\Promise\PromiseInterface::getState()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="resolve" id="_resolve">
<td class="attributes"><code>
public
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_resolve">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#93-96" title="Go to source code">resolve</a>( <span>mixed <var>$value</var></span> )</code>
<div class="description short">
<p>Resolve the promise with the given value.</p>
</div>
<div class="description detailed hidden">
<p>Resolve the promise with the given value.</p>
<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$value</var></dt>
<dd></dd>
</dl></div>
<h4>Throws</h4>
<div class="list">
RuntimeException<br>if the promise is already resolved.
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_resolve">GuzzleHttp\Promise\PromiseInterface::resolve()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="reject" id="_reject">
<td class="attributes"><code>
public
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_reject">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#98-101" title="Go to source code">reject</a>( <span>mixed <var>$reason</var></span> )</code>
<div class="description short">
<p>Reject the promise with the given reason.</p>
</div>
<div class="description detailed hidden">
<p>Reject the promise with the given reason.</p>
<h4>Parameters</h4>
<div class="list"><dl>
<dt><var>$reason</var></dt>
<dd></dd>
</dl></div>
<h4>Throws</h4>
<div class="list">
RuntimeException<br>if the promise is already resolved.
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_reject">GuzzleHttp\Promise\PromiseInterface::reject()</a></code></div>
</div>
</div></td>
</tr>
<tr data-order="cancel" id="_cancel">
<td class="attributes"><code>
public
</code>
</td>
<td class="name"><div>
<a class="anchor" href="#_cancel">#</a>
<code><a href="source-class-GuzzleHttp.Promise.Coroutine.html#103-107" title="Go to source code">cancel</a>( )</code>
<div class="description short">
<p>Cancels the promise if possible.</p>
</div>
<div class="description detailed hidden">
<p>Cancels the promise if possible.</p>
<h4>Link</h4>
<div class="list">
<a href="https://github.com/promises-aplus/cancellation-spec/issues/7">https://github.com/promises-aplus/cancellation-spec/issues/7</a><br>
</div>
<h4>Implementation of</h4>
<div class="list"><code><a href="class-GuzzleHttp.Promise.PromiseInterface.html#_cancel">GuzzleHttp\Promise\PromiseInterface::cancel()</a></code></div>
</div>
</div></td>
</tr>
</table>
<table class="summary inherited">
<caption>Constants inherited from <a href="class-GuzzleHttp.Promise.PromiseInterface.html#constants">GuzzleHttp\Promise\PromiseInterface</a></caption>
<tr>
<td><code>
<a href="class-GuzzleHttp.Promise.PromiseInterface.html#FULFILLED"><b>FULFILLED</b></a>,
<a href="class-GuzzleHttp.Promise.PromiseInterface.html#PENDING"><b>PENDING</b></a>,
<a href="class-GuzzleHttp.Promise.PromiseInterface.html#REJECTED"><b>REJECTED</b></a>
</code></td>
</tr>
</table>
</div>
<div id="footer">
ξ ^ω^)ξ Baguette PHP Mastodon API Client / SDK API documentation generated by <a href="http://apigen.org">ApiGen</a>
</div>
</div>
</div>
<script src="resources/combined.js"></script>
<script src="elementlist.js"></script>
</body>
</html>