9
9
use Amp \Serialization \NativeSerializer ;
10
10
use Amp \Serialization \SerializationException ;
11
11
use Amp \Serialization \Serializer ;
12
- use Revolt \EventLoop ;
13
12
14
13
/** @internal */
15
14
function runContext (
@@ -19,73 +18,69 @@ function runContext(
19
18
array $ argv ,
20
19
Serializer $ serializer = new NativeSerializer (),
21
20
): void {
22
- EventLoop::queue (function () use ($ argv , $ uri , $ key , $ connectCancellation , $ serializer ): void {
23
- /** @noinspection PhpUnusedLocalVariableInspection */
24
- $ argc = \count ($ argv );
21
+ /** @noinspection PhpUnusedLocalVariableInspection */
22
+ $ argc = \count ($ argv );
25
23
26
- try {
27
- $ socket = Ipc \connect ($ uri , $ key , $ connectCancellation );
28
- $ ipcChannel = new StreamChannel ($ socket , $ socket , $ serializer );
29
-
30
- $ socket = Ipc \connect ($ uri , $ key , $ connectCancellation );
31
- $ resultChannel = new StreamChannel ($ socket , $ socket , $ serializer );
32
- } catch (\Throwable $ exception ) {
33
- \trigger_error ($ exception ->getMessage (), E_USER_ERROR );
34
- }
35
-
36
- try {
37
- if (!isset ($ argv [0 ])) {
38
- throw new \Error ("No script path given " );
39
- }
24
+ try {
25
+ $ socket = Ipc \connect ($ uri , $ key , $ connectCancellation );
26
+ $ ipcChannel = new StreamChannel ($ socket , $ socket , $ serializer );
40
27
41
- if (!\is_file ($ argv [0 ])) {
42
- throw new \Error (\sprintf (
43
- "No script found at '%s' (be sure to provide the full path to the script) " ,
44
- $ argv [0 ],
45
- ));
46
- }
28
+ $ socket = Ipc \connect ($ uri , $ key , $ connectCancellation );
29
+ $ resultChannel = new StreamChannel ($ socket , $ socket , $ serializer );
30
+ } catch (\Throwable $ exception ) {
31
+ \trigger_error ($ exception ->getMessage (), E_USER_ERROR );
32
+ }
47
33
48
- try {
49
- // Protect current scope by requiring script within another function.
50
- // Using $argc, so it is available to the required script.
51
- $ callable = (function () use ($ argc , $ argv ): callable {
52
- /** @psalm-suppress UnresolvableInclude */
53
- return require $ argv [0 ];
54
- })();
55
- } catch (\TypeError $ exception ) {
56
- throw new \Error (\sprintf (
57
- "Script '%s' did not return a callable function: %s " ,
58
- $ argv [0 ],
59
- $ exception ->getMessage (),
60
- ), 0 , $ exception );
61
- } catch (\ParseError $ exception ) {
62
- throw new \Error (\sprintf (
63
- "Script '%s' contains a parse error: %s " ,
64
- $ argv [0 ],
65
- $ exception ->getMessage (),
66
- ), 0 , $ exception );
67
- }
34
+ try {
35
+ if (!isset ($ argv [0 ])) {
36
+ throw new \Error ("No script path given " );
37
+ }
68
38
69
- $ returnValue = $ callable (new ContextChannel ($ ipcChannel ));
70
- $ result = new ExitSuccess ($ returnValue instanceof Future ? $ returnValue ->await () : $ returnValue );
71
- } catch (\Throwable $ exception ) {
72
- $ result = new ExitFailure ($ exception );
39
+ if (!\is_file ($ argv [0 ])) {
40
+ throw new \Error (\sprintf (
41
+ "No script found at '%s' (be sure to provide the full path to the script) " ,
42
+ $ argv [0 ],
43
+ ));
73
44
}
74
45
75
46
try {
76
- try {
77
- $ resultChannel ->send ($ result );
78
- } catch (SerializationException $ exception ) {
79
- // Serializing the result failed. Send the reason why.
80
- $ resultChannel ->send (new ExitFailure ($ exception ));
81
- }
82
- } catch (\Throwable $ exception ) {
83
- \trigger_error (\sprintf (
84
- "Could not send result to parent: '%s'; be sure to shutdown the child before ending the parent " ,
47
+ // Protect current scope by requiring script within another function.
48
+ // Using $argc, so it is available to the required script.
49
+ $ callable = (function () use ($ argc , $ argv ): callable {
50
+ /** @psalm-suppress UnresolvableInclude */
51
+ return require $ argv [0 ];
52
+ })();
53
+ } catch (\TypeError $ exception ) {
54
+ throw new \Error (\sprintf (
55
+ "Script '%s' did not return a callable function: %s " ,
56
+ $ argv [0 ],
57
+ $ exception ->getMessage (),
58
+ ), 0 , $ exception );
59
+ } catch (\ParseError $ exception ) {
60
+ throw new \Error (\sprintf (
61
+ "Script '%s' contains a parse error: %s " ,
62
+ $ argv [0 ],
85
63
$ exception ->getMessage (),
86
- ), E_USER_ERROR );
64
+ ), 0 , $ exception );
87
65
}
88
- });
89
66
90
- EventLoop::run ();
67
+ $ returnValue = $ callable (new ContextChannel ($ ipcChannel ));
68
+ $ result = new ExitSuccess ($ returnValue instanceof Future ? $ returnValue ->await () : $ returnValue );
69
+ } catch (\Throwable $ exception ) {
70
+ $ result = new ExitFailure ($ exception );
71
+ }
72
+
73
+ try {
74
+ try {
75
+ $ resultChannel ->send ($ result );
76
+ } catch (SerializationException $ exception ) {
77
+ // Serializing the result failed. Send the reason why.
78
+ $ resultChannel ->send (new ExitFailure ($ exception ));
79
+ }
80
+ } catch (\Throwable $ exception ) {
81
+ \trigger_error (\sprintf (
82
+ "Could not send result to parent: '%s'; be sure to shutdown the child before ending the parent " ,
83
+ $ exception ->getMessage (),
84
+ ), E_USER_ERROR );
85
+ }
91
86
}
0 commit comments