温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/Spawn/BaseOptions/ipc
点击访问原文链接

BaseOptions.ipc method | Bun module | Bun

BaseOptions.ipc method | Bun module | BunBuildDocsReferenceGuidesBlogDiscord/Bun/Spawn/BaseOptions/ipcMipc

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/Spawn/BaseOptions/ipcMipc

method

Spawn.BaseOptions.ipcipc(message: any,subprocess: SubprocessIn, Out, Err>,handle?: unknown): void;

When specified, Bun will open an IPC channel to the subprocess. The passed callback is called for incoming messages, and subprocess.send can send messages to the subprocess. Messages are serialized using the JSC serialize API, which allows for the same types that postMessage/structuredClone supports.

The subprocess can send and receive messages by using process.send and process.on("message"), respectively. This is the same API as what Node.js exposes when child_process.fork() is used.

Currently, this is only compatible with processes that are other bun instances.

@param subprocess

The Subprocess that received the message

Referenced typesinterface SubprocessIn extends SpawnOptions.Writable = SpawnOptions.Writable, Out extends SpawnOptions.Readable = SpawnOptions.Readable, Err extends SpawnOptions.Readable = SpawnOptions.Readable>

A process created by Bun.spawn.

This type accepts 3 optional type parameters which correspond to the stdio array from the options object. Instead of specifying these, you should use one of the following utility types instead:

ReadableSubprocess (any, pipe, pipe)WritableSubprocess (pipe, any, any)PipedSubprocess (pipe, pipe, pipe)NullSubprocess (ignore, ignore, ignore)
readonly exitCode: null | number

Synchronously get the exit code of the process

If the process hasn't exited yet, this will return null

readonly exited: Promisenumber>

The exit code of the process

The promise will resolve when the process exits

readonly killed: boolean

Has the process exited?

readonly pid: number

The process ID of the child process

const { pid } = Bun.spawn({ cmd: ["echo", "hello"] });
console.log(pid); // 1234
readonly readable: ReadableToIOOut>

This returns the same value as Subprocess.stdout

It exists for compatibility with ReadableStream.pipeThrough

readonly signalCode: null | Signals

Synchronously get the signal code of the process

If the process never sent a signal code, this will return null

To receive signal code changes, use the onExit callback.

If the signal code is unknown, it will return the original signal code number, but that case should essentially never happen.

readonly stderr: ReadableToIOErr>readonly stdin: WritableToIOIn>readonly stdio: [null, null, null, ...null | number[]]

Access extra file descriptors passed to the stdio option in the options object.

Entries beyond index 2 are number for "pipe" slots and, on POSIX, for slots where a raw file descriptor was supplied (the same fd is returned; it remains owned by the caller and is never closed by the subprocess). Other slots — including raw fds on Windows — are null.

readonly stdout: ReadableToIOOut>readonly terminal: undefined | Terminal

The terminal attached to this subprocess, if spawned with the terminal option. Returns undefined if no terminal was attached.

When a terminal is attached, stdin, stdout, and stderr return null. Use terminal.write() and the data callback instead.

const proc = Bun.spawn(["bash"], {
terminal: { data: (term, data) => console.log(data.toString()) },
});

proc.terminal?.write("echo hello\n");
[Symbol.asyncDispose](): PromiseLikevoid>;disconnect(): void;

Disconnect the IPC channel to the subprocess. This is only supported if the subprocess was created with the ipc option.

kill(exitCode?: number | Signals): void;

Kill the process

@param exitCode

The exitCode to send to the process

ref(): void;

This method will tell Bun to wait for this process to exit after you already called unref().

Before shutting down, Bun will wait for all subprocesses to exit by default

resourceUsage(): undefined | ResourceUsage;

Get the resource usage information of the process (max RSS, CPU time, etc)

Only available after the process has exited

If the process hasn't exited yet, this will return undefined

send(message: any): void;

Send a message to the subprocess. This is only supported if the subprocess was created with the ipc option, and is another instance of bun.

Messages are serialized using the JSC serialize API, which allows for the same types that postMessage/structuredClone supports.

unref(): void;

Before shutting down, Bun will wait for all subprocesses to exit by default

This method will tell Bun to not wait for this process to exit before shutting down.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

BaseOptions.ipc method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun.Spawn.BaseOptions.ipc | Bun