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])); } // Protect current scope by requiring script within another function. $callable = (function () use ($argc, $argv) { // Using $argc so it is available to the required script. return require $argv[0]; })(); if (!\is_callable($callable)) { throw new \Error(\sprintf("Script '%s' did not return a callable function", $argv[0])); } $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) { 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); } })();