Skip to content

Commit

Permalink
$mol_run fallback to sync spawn otside fiber - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Oct 23, 2024
1 parent e0c40ea commit 2b112e2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions run/run.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace $ {

export type $mol_run_error_context = {
pid?: number
stdout: Buffer
stderr: Buffer
stdout: Buffer | string
stderr: Buffer | string
status?: number | null
signal: NodeJS.Signals | null,
}
Expand All @@ -17,9 +17,13 @@ namespace $ {
dir: string
}> {}

const child_process = $node['child_process']
export const $mol_run_spawn = child_process.spawn.bind(child_process)
export const $mol_run_spawn_sync = child_process.spawnSync.bind(child_process)
export const $mol_run_spawn = (
...args: Parameters<typeof $node['child_process']['spawn']>
) => $node['child_process'].spawn(...args)

export const $mol_run_spawn_sync = (
...args: Parameters<typeof $node['child_process']['spawnSync']>
) => $node['child_process'].spawnSync(...args)

export type $mol_run_options = {
command : readonly string[] | string
Expand Down Expand Up @@ -60,8 +64,6 @@ namespace $ {
let pid = 0

if (sync) {
let error: Error | undefined
let res

this.$.$mol_log3_warn({
place: '$mol_run_async',
Expand All @@ -70,14 +72,17 @@ namespace $ {
...log_object
})

let error: Error | undefined
let res

try {
res = this.$.$mol_run_spawn_sync(app, args, opts)
error = res.error
} catch (err) {
error = err as Error
}

if (error || res?.status) {
if (! res || error || res.status) {
throw new $mol_run_error(
this.error_message(res),
{ ...log_object, pid, status: res?.status, signal: res?.signal },
Expand Down

0 comments on commit 2b112e2

Please sign in to comment.