Suppose I have the following snippet to create a worker in Deno and start it.
const worker = new Worker("./worker.ts", { type: "module", deno: true });
worker.postMessage({ command: "START" });
Is there a way to pipe stdout/stderr from the worker to a file, similarly to how Deno.run
works? For example, is something like this possible?
const file = await Deno.open('/path/to/file.log', { write: true });
const worker = new Worker("./worker.ts", {
type: "module",
deno: true,
stdout: file.rid,
stderr: file.rid
});
worker.postMessage({ command: "START" });
Or, is it possible to use a stream?
import { WritableStream } from "https://denopkg.com/keroxp/deno-streams/writable_stream.ts"
const stream = new WritableStream<number>({
write: chunk => {
...
}
})
const worker = new Worker("./worker.ts", {
type: "module",
deno: true,
stdout: stream,
stderr: stream
});
worker.postMessage({ command: "START" });