Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

38
dependencies/amphp/amp/lib/Producer.php vendored Normal file
View File

@ -0,0 +1,38 @@
<?php
namespace WP_Ultimo\Dependencies\Amp;
/**
* @template-covariant TValue
* @template-implements Iterator<TValue>
*/
final class Producer implements Iterator
{
/**
* @use Internal\Producer<TValue>
*/
use CallableMaker, Internal\Producer;
/**
* @param callable(callable(TValue):Promise):\Generator $producer
*
* @throws \Error Thrown if the callable does not return a Generator.
*/
public function __construct(callable $producer)
{
$result = $producer($this->callableFromInstanceMethod("emit"));
if (!$result instanceof \Generator) {
throw new \Error("The callable did not return a Generator");
}
$coroutine = new Coroutine($result);
$coroutine->onResolve(function ($exception) {
if ($this->complete) {
return;
}
if ($exception) {
$this->fail($exception);
return;
}
$this->complete();
});
}
}