0.6.2 • Published 11 months ago
@delight-rpc/child-process v0.6.2
@delight-rpc/child-process
Install
npm install --save @delight-rpc/child-process
# or
yarn add @delight-rpc/child-process
Usage
Main as Client, ChildProcess as Server
// api.d.ts
interface IAPI {
echo(message: string): string
}
// child-process.ts
import { createServer } from '@delight-rpc/child-process'
const api: IAPI = {
echo(message: string): string {
return message
}
}
createServer(api, process)
// main.ts
import { fork } from 'child_process'
import { createClient } from '@delight-rpc/child-process'
const childProcess = fork('./child-process.js', { serialization: 'advanced' })
const [client] = createClient<IAPI>(childProcess)
await client.echo('hello world')
ChildProcess as Client, Main as Server
// api.d.ts
interface IAPI {
echo(message: string): string
}
// main.ts
import { fork } from 'child_process'
import { createServer } from '@delight-rpc/child-process'
const api: IAPI = {
echo(message: string): string {
return message
}
}
const childProcess = fork('./child-process.js', { serialization: 'advanced' })
createServer(api, childProcess)
// child-process.ts
import { createClient } from '@delight-rpc/child-process'
const [client] = createClient<IAPI>(process)
await client.echo('hello world')
API
createClient
function createClient<IAPI extends object>(
process: ChildProcess | NodeJS.Process
, options?: {
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
expectedVersion?: string
channel?: string
}
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void]
createBatchClient
function createBatchClient<DataType>(
process: ChildProcess | NodeJS.Process
, options?: {
expectedVersion?: string
channel?: string
}
): [client: DelightRPC.BatchClient<DataType>, close: () => void]
createServer
function createServer<IAPI extends object>(
api: DelightRPC.ImplementationOf<IAPI>
, process: ChildProcess | NodeJS.Process
, options?: {
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
version?: `${number}.${number}.${number}`
channel?: string | RegExp | AnyChannel
ownPropsOnly?: boolean
}
): () => void
0.6.2
11 months ago
0.6.1
1 year ago
0.6.0
1 year ago
0.5.2
1 year ago
0.5.1
1 year ago
0.5.0
1 year ago
0.4.5
2 years ago
0.4.6
2 years ago
0.4.4
2 years ago
0.4.3
2 years ago
0.4.1
2 years ago
0.4.0
2 years ago
0.4.2
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.2.6
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago