(input: {
readonly command: string;
readonly args: ReadonlyArray<string>;
readonly env: Record<string, string | undefined>;
})
| 141 | // --------------------------------------------------------------------------- |
| 142 | |
| 143 | export const spawnDetached = (input: { |
| 144 | readonly command: string; |
| 145 | readonly args: ReadonlyArray<string>; |
| 146 | readonly env: Record<string, string | undefined>; |
| 147 | }): Effect.Effect<SpawnedDetachedProcess, Error> => |
| 148 | Effect.try({ |
| 149 | try: () => { |
| 150 | const child = spawn(input.command, [...input.args], { |
| 151 | detached: true, |
| 152 | stdio: "ignore", |
| 153 | env: input.env, |
| 154 | }); |
| 155 | child.unref(); |
| 156 | if (typeof child.pid !== "number") { |
| 157 | child.kill(); |
| 158 | throw new Error("Failed to spawn daemon process: child pid was not assigned"); |
| 159 | } |
| 160 | return { pid: child.pid }; |
| 161 | }, |
| 162 | catch: (cause) => |
| 163 | cause instanceof Error |
| 164 | ? cause |
| 165 | : new Error(`Failed to spawn daemon process: ${String(cause)}`), |
| 166 | }); |
| 167 | |
| 168 | const signalPid = (pid: number): Effect.Effect<void, Error> => |
| 169 | Effect.try({ |
no outgoing calls
no test coverage detected