An open API service indexing awesome lists of open source software.

https://github.com/delight-rpc/piscina

🌿
https://github.com/delight-rpc/piscina

esm library nodejs npm-package typescript

Last synced: 3 months ago
JSON representation

🌿

Awesome Lists containing this project

README

          

# @delight-rpc/piscina
## Install
```sh
npm install --save @delight-rpc/piscina
# or
yarn add @delight-rpc/piscina
```

## Usage
```ts
// 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
}
}

const [handler] = createServer(api)

export default handler

// main.ts
import { createClient } from '@delight-rpc/piscina'

const piscina = new Piscina({
filename: new URL('./worker.js', import.meta.url).href
})
const [client] = createClient(piscina)

await client.echo('hello world')
```

## API
### createClient
```ts
function createClient(
piscina: Piscina
, options?: {
parameterValidators?: DelightRPC.ParameterValidators
expectedVersion?: string
channel?: string
timeout?: number
}
): [client: DelightRPC.ClientProxy, close: () => void]
```

### createBatchClient
```ts
function createBatchClient(
piscina: Piscina
, options?: {
expectedVersion?: string
channel?: string
timeout?: number
}
): [client: DelightRPC.BatchClient, close: () => void]
```

### createServer
```ts
function createServer(
api: DelightRPC.ImplementationOf
, options?: {
parameterValidators?: DelightRPC.ParameterValidators
version?: `${number}.${number}.${number}`
channel?: string | RegExp | AnyChannel
ownPropsOnly?: boolean
}
): [handler: (message: unknown) => Promise, close: () => void]
```