@delight-rpc/piscina
v0.5.5
Published
```sh npm install --save @delight-rpc/piscina # or yarn add @delight-rpc/piscina ```
Downloads
26
Readme
@delight-rpc/piscina
Install
npm install --save @delight-rpc/piscina
# or
yarn add @delight-rpc/piscina
Usage
// api.d.ts
interface IAPI {
echo(message: string): string
}
// worker.ts
import { createServer } from '@delight-rpc/piscina'
const api: IAPI = {
echo(message: string): string {
return message
}
}
export default createServer(api)
// main.ts
import { createClient } from '@delight-rpc/piscina'
const piscina = new Piscina({
filename: new URL('./worker.js', import.meta.url).href
})
const client = createClient<IAPI>(piscina)
await client.echo('hello world')
API
createClient
function createClient<IAPI extends object>(
piscina: Piscina
, options?: {
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
expectedVersion?: string
channel?: string
}
): DelightRPC.ClientProxy<IAPI>
createBatchClient
function createBatchClient<DataType>(
piscina: Piscina
, options?: {
expectedVersion?: string
channel?: string
}
): DelightRPC.BatchClient<DataType>
createServer
function createServer<IAPI extends object>(
api: DelightRPC.ImplementationOf<IAPI>
, options?: {
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
version?: `${number}.${number}.${number}`
channel?: string
ownPropsOnly?: boolean
channel?: string | RegExp | AnyChannel
}
): (req: unknown) => Promise<unknown>