Skip to content

Commit

Permalink
🐛 debug
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Sep 3, 2024
1 parent bd49f61 commit 625bac4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/yflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Flow\Job\YJob;
use Flow\JobInterface;

$driver = match (random_int(1, 4)) {
$driver = match (random_int(3, 3)) {
1 => new AmpDriver(),

Check failure on line 21 in examples/yflow.php

View workflow job for this annotation

GitHub Actions / Execute PHPStan analysis (8.3)

Match arm comparison between 3 and 1 is always false.
2 => new ReactDriver(),

Check failure on line 22 in examples/yflow.php

View workflow job for this annotation

GitHub Actions / Execute PHPStan analysis (8.3)

Match arm comparison between 3 and 2 is always false.
3 => new FiberDriver(),
Expand Down Expand Up @@ -162,15 +162,15 @@ function factorialYMemo(int $n): int
) {
yield [$factorialJob];
yield [$factorialYJobBefore];
yield new YFlow($factorialYJob);
yield [$factorialYJobAfter];
yield [$factorialYMemoJob];
yield [$factorialYJobDeferBefore];
yield [$factorialYJobDefer, null, null, null, new DeferAsyncHandler()];
yield [$factorialYJobDeferAfter, null, null, null, new DeferAsyncHandler()];
//yield new YFlow($factorialYJob);
//yield [$factorialYJobAfter];
//yield [$factorialYMemoJob];
//yield [$factorialYJobDeferBefore];
//yield [$factorialYJobDefer, null, null, null, new DeferAsyncHandler()];
//yield [$factorialYJobDeferAfter, null, null, null, new DeferAsyncHandler()];
}, ['driver' => $driver]);

for ($i = 1; $i <= 5; $i++) {
for ($i = 1; $i <= 1; $i++) {
$ip = new Ip(new YFlowData($i, $i));
$flow($ip);
}
Expand Down
3 changes: 3 additions & 0 deletions src/AsyncHandler/AsyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function async(AsyncEvent $event): void
$asyncJob = $async($event->getJob());

$popIp = $this->ipPool->addIp($ip);

printf('async'."\n");
$next = $asyncJob($ip->data);
$next(static function ($data) use ($event, $popIp) {
$event->getCallback()($data);
Expand All @@ -51,6 +53,7 @@ public function async(AsyncEvent $event): void

public function pool(PoolEvent $event): void
{

$event->setIps($this->ipPool->getIps());
}
}
3 changes: 3 additions & 0 deletions src/Driver/FiberDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public function await(array &$stream): void
do {
foreach ($stream['dispatchers'] as $index => $dispatcher) {
$nextIp = $dispatcher->dispatch(new PullEvent(), Event::PULL)->getIp();

if ($nextIp !== null) {
printf('nextip '.$this->countIps($stream['dispatchers'])."\n");
$stream['dispatchers'][$index]->dispatch(new AsyncEvent(static function (Closure|JobInterface $job) use ($async) {
return $async(false)($job);
}, static function (Closure|JobInterface $job) use ($defer) {
Expand Down Expand Up @@ -168,6 +170,7 @@ public function await(array &$stream): void
}

$tick++;
printf('count '.$this->countIps($stream['dispatchers'])."\n");
} while ($this->countIps($stream['dispatchers']) > 0 or count($this->ticks) > 0);
}

Expand Down
2 changes: 2 additions & 0 deletions src/IpStrategy/LinearIpStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function getSubscribedEvents(): array
*/
public function push(PushEvent $event): void
{
printf('push'."\n");
$this->ips[] = $event->getIp();
}

Expand All @@ -45,6 +46,7 @@ public function push(PushEvent $event): void
*/
public function pull(PullEvent $event): void
{
printf('pull'."\n");
$event->setIp(array_shift($this->ips));
}

Expand Down

0 comments on commit 625bac4

Please sign in to comment.