@zeing/ipc
v0.1.4
Published
Lightweight TCP-based RPC IPC library for Bun
Readme
@zeing/ipc
Lightweight TCP-based RPC IPC library for Bun. Uses msgpackr for fast binary serialization.
Note: This is built for personal use. I don't guarantee it will work for your project.
Requirements
- Bun runtime
Installation
bun add @zeing/ipcUsage
Server
import { IpcServer } from '@zeing/ipc'
const server = new IpcServer(9000)
server.register('greet', (data: { name: string }) => {
return `Hello, ${data.name}`
})
server.start()Client
import { IpcClient } from '@zeing/ipc'
const client = new IpcClient(9000)
await client.connect()
const result = await client.call<string>('greet', { name: 'World' })
console.log(result) // Hello, World
client.disconnect()Custom timeout
// Default timeout is 30 seconds
const result = await client.call('slowMethod', data, 60_000)API
IpcServer
| Method | Description |
|--------|-------------|
| new IpcServer(port) | Create server on given port (binds to 127.0.0.1) |
| register(method, handler) | Register a handler for a method name |
| start() | Start listening |
IpcClient
| Method | Description |
|--------|-------------|
| new IpcClient(port) | Create client targeting given port |
| connect() | Connect to the server |
| call<T>(method, data?, timeoutMs?) | Call a remote method, returns Promise<T> |
| disconnect() | Disconnect and clean up |
| getPendingCount() | Number of in-flight requests |
License
MIT
