Skip to content

Commit

Permalink
Deprecate Await::f2c and Await::g2c, use Await::run instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Mar 20, 2022
1 parent 9e290d3 commit a75f087
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions await-generator/src/SOFe/AwaitGenerator/Await.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,30 @@ class Await extends PromiseState{
protected final function __construct(){
}

/**
* Executes a generator in the background.
*
* @param Closure|Generator $generator
* @phpstan-param Generator<mixed, Await::RESOLVE|null|Await::RESOLVE_MULTI|Await::REJECT|Await::ONCE|Await::ALL|Await::RACE|Generator, mixed, T>|Closure(): Generator<mixed, Await::RESOLVE|null|Await::RESOLVE_MULTI|Await::REJECT|Await::ONCE|Await::ALL|Await::RACE|Generator, mixed, T> $generator
*/
public static function run(Closure|Generator $generator) : void{
if($generator instanceof Closure) {
$generator = $generator();
}

/** @var Await<T> $await */
$await = new Await();
$await->generator = $generator;
$await->onComplete = null;

$await->wakeupFlat(fn() => $generator->rewind());
}

/**
* Converts a `Function<AwaitGenerator>` to a VoidCallback
*
* @deprecated Use `Await::run` instead.
*
* @param callable $closure
* @phpstan-param callable(): Generator<mixed, Await::RESOLVE|null|Await::RESOLVE_MULTI|Await::REJECT|Await::ONCE|Await::ALL|Await::RACE|Generator, mixed, T> $closure
* @param callable|null $onComplete
Expand All @@ -101,6 +122,8 @@ public static function f2c(callable $closure, ?callable $onComplete = null, $cat
/**
* Converts an AwaitGenerator to a VoidCallback
*
* @deprecated Use `Await::run` instead.
*
* @param Generator $generator
* @phpstan-param Generator<mixed, Await::RESOLVE|null|Await::RESOLVE_MULTI|Await::REJECT|Await::ONCE|Await::ALL|Await::RACE|Generator, mixed, T> $generator
* @param callable|null $onComplete
Expand Down

0 comments on commit a75f087

Please sign in to comment.