Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #106 +/- ##
============================================
- Coverage 99.45% 93.12% -6.33%
- Complexity 129 144 +15
============================================
Files 10 10
Lines 367 393 +26
============================================
+ Hits 365 366 +1
- Misses 2 27 +25
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
|
I don't think it helps, but I came up with the following for the basic annotations /**
* Wraps a generator that executes some action before and after suspension points (`yield`s).
* @phpstan-template TKey
* @phpstan-template TValue
* @phpstan-template TSend
* @phpstan-template TReturn
* @phpstan-param Generator<TKey, TValue, TSend, TReturn> $generator
* @phpstan-param Closure(Generator, TValue, TKey): bool $beforeSuspend
* @phpstan-param Closure(Generator, TValue, TKey, TSend): bool $afterSuspend
* @phpstan-return Generator<TKey, TValue, TSend, TReturn>
*/
public static function trap(Generator $generator, Closure $beforeSuspend, Closure $afterSuspend) : Generator { |
Please send a pull request |
|
How to use this? Does it run the closures for every |
Yep, and you can intercept the signals to see what it is suspending for. |
|
No idea how to use sorry. <?php
declare(strict_types=1);
require("../../vendor/autoload.php");
function gen() : Generator
{
yield from gen2();
}
function gen2() : Generator
{
yield from [];
}
\SOFe\AwaitGenerator\Await::f2c(function () : Generator {
yield from \SOFe\AwaitGenerator\Await::trap(
gen(),
fn (...$args) => var_dump(
"a1",
$args
),
fn (...$args) => var_dump(
"a2",
$args
)
);
}); |
For example, the I am thinking about providing a better API so that I don't have to expose the internal constants like |
|
Oh I didn't realise there is a test file. |
No description provided.