send($key)); } catch (\Throwable $exception) { \trigger_error("Could not send key to parent", E_USER_ERROR); exit(1); } try { 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])); } try { // Protect current scope by requiring script within another function. $callable = (function () use ($argc, $argv): callable { // Using $argc so it is available to the required script. return require $argv[0]; })(); } catch (\TypeError $exception) { throw new \Error(\sprintf("Script '%s' did not return a callable function", $argv[0]), 0, $exception); } catch (\ParseError $exception) { throw new \Error(\sprintf("Script '%s' contains a parse error: " . $exception->getMessage(), $argv[0]), 0, $exception); } $result = new Sync\ExitSuccess(Promise\wait(call($callable, $channel))); } catch (\Throwable $exception) { $result = new Sync\ExitFailure($exception); } try { Promise\wait(call(function () use ($channel, $result): \Generator { 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) { \trigger_error("Could not send result to parent; be sure to shutdown the child before ending the parent", E_USER_ERROR); exit(1); } })();