send($key); } catch (\Throwable $exception) { \trigger_error(E_USER_ERROR, "Could not send key to parent"); 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(yield call($callable, $channel)); } 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) { \trigger_error(E_USER_ERROR, "Could not send result to parent"); exit(1); } });