#Cross Child-Process Communication

1 messages · Page 1 of 1 (latest)

wintry comet
#

Doing something simple where I would spawn a websocket and an HTTP server and allow them to communicate between eachother.

https://bun.sh/guides/process/ipc

I've read the post history on here, but cannot find a solid example.

What should be expected is that they return a process or that I would be able to pass the processes into each other to make proper references but that doesn't seem possible. Is there a more complex example implementation so I can actually put this to work? Is it standard to make an additional process on top of this in some way to allow for this? Just doesn't make sense if I can't pass the process around or between these two entities in an expected way.

const webserver = Bun.spawn(["bun", "webserver.js"], {
    ipc(message) {
        console.log("Webserver message received", message)
    }
})

console.log("Webserver spawned", webserver)

const websocket = Bun.spawn(["bun", "websocket.js"], {
    ipc(message) {
        console.log("Websocket message received", message)
    }
})

console.log("Websocket spawned", websocket)
#

Cross Child-Process Communication