Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
paperdave committed Sep 5, 2023
1 parent 9c63352 commit a9b6848
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3767,6 +3767,24 @@ declare module "bun" {
*/
error?: Errorlike,
): void | Promise<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 recieve 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.
*/
ipc?(
message: any,
/**
* The {@link Subprocess} that sent the message
*/
subprocess: Subprocess<In, Out, Err>,
): void;
}

type OptionsToSubprocess<Opts extends OptionsObject> =
Expand Down Expand Up @@ -3894,6 +3912,20 @@ declare module "bun" {
* This method will tell Bun to not wait for this process to exit before shutting down.
*/
unref(): 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.
*/
send(message: any): void;

/**
* Disconnect the IPC channel to the subprocess. This is only supported if the subprocess
* was created with the `ipc` option.
*/
disconnect(): void;
}

/**
Expand Down

0 comments on commit a9b6848

Please sign in to comment.