Skip to content

Commit

Permalink
🎨 not using channels way
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Apr 21, 2021
1 parent e0ab738 commit 39ee2e6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Adapter/Swoole/Internal/SwoolePromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,39 +180,45 @@ public static function all(iterable $promises): SwoolePromise
$ticks = count($promises);

$firstError = null;
$channel = new Channel($ticks);
//$channel = new Channel($ticks);
$result = [];
$key = 0;
foreach ($promises as $promise) {
if (!$promise instanceof SwoolePromise) {
$channel->close();
//$channel->close();
throw new RuntimeException(
'Supported only SwoolePromise instance'
);
}
$promise->then(function ($value) use ($key, &$result, $channel) {
$promise->then(function ($value) use ($key, &$result, &$ticks, $resolve/* $channel*/) {
$result[$key] = $value;
$channel->push(true);
$ticks--;
//$channel->push(true);
if($ticks === 0) {
$resolve($result);
}
return $value;
}, function ($error) use ($channel, &$firstError) {
$channel->push(true);
}, function ($error) use (/*$channel, */&$firstError, &$ticks, $reject) {
//$channel->push(true);
$ticks--;
if ($firstError === null) {
$firstError = $error;
$reject($firstError);
}
});
$key++;
}
while ($ticks--) {
$channel->pop();
}
$channel->close();
//while ($ticks--) {
// $channel->pop();
//}
//$channel->close();

if ($firstError !== null) {
/*if ($firstError !== null) {
$reject($firstError);
return;
}
$resolve($result);
$resolve($result);*/
});
}

Expand Down

0 comments on commit 39ee2e6

Please sign in to comment.