fix looping errors
This commit is contained in:
parent
466239d0e6
commit
8aac0b8bde
1 changed files with 11 additions and 8 deletions
|
@ -53,17 +53,20 @@ export function loop_process(
|
||||||
on_start: opts?.on_start ?? async_noop,
|
on_start: opts?.on_start ?? async_noop,
|
||||||
on_stop: opts?.on_stop ?? async_noop,
|
on_stop: opts?.on_stop ?? async_noop,
|
||||||
};
|
};
|
||||||
|
const control = {
|
||||||
|
do_continue: true,
|
||||||
|
child_process: null as null | Deno.ChildProcess,
|
||||||
|
};
|
||||||
const kill_sig = channel<"kill">();
|
const kill_sig = channel<"kill">();
|
||||||
|
kill_sig.receive().then(() => {
|
||||||
|
control.do_continue = false;
|
||||||
|
control.child_process?.kill();
|
||||||
|
});
|
||||||
async function launch() {
|
async function launch() {
|
||||||
while (true) {
|
while (control.do_continue) {
|
||||||
await events.on_start();
|
await events.on_start();
|
||||||
const child_process = command.spawn();
|
control.child_process = command.spawn();
|
||||||
const result = await Promise.any([kill_sig.receive(), child_process.output()]);
|
await control.child_process.output();
|
||||||
if (result === "kill") {
|
|
||||||
await events.on_stop();
|
|
||||||
child_process.kill();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
await events.on_stop();
|
await events.on_stop();
|
||||||
await sleep(opts?.delay ?? 500);
|
await sleep(opts?.delay ?? 500);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue