send($key); } catch (\Throwable $exception) { exit(1); // Parent context died, simply exit. } try { // Protect current scope by requiring script within another function. $callable = (function () use ($argc, $argv): callable { if (!isset($argv[0])) { throw new \Error("No script path given"); } if (!\is_file($argv[0])) { throw new \Error(\sprintf("No script found at '%s' (be sure to provide the full path to the script)", $argv[0])); } $callable = require $argv[0]; if (!\is_callable($callable)) { throw new \Error(\sprintf("Script '%s' did not return a callable function", $argv[0])); } return $callable; })(); $result = new Sync\ExitSuccess(yield call($callable, $channel)); } catch (Sync\ChannelException $exception) { exit(1); // Parent context died, simply exit. } catch (\Throwable $exception) { $result = new Sync\ExitFailure($exception); } try { try { yield $channel->send($result); } catch (Sync\SerializationException $exception) { // Serializing the result failed. Send the reason why. yield $channel->send(new Sync\ExitFailure($exception)); } } catch (\Throwable $exception) { exit(1); // Parent context died, simply exit. } });