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
🌿
- Host: GitHub
- URL: https://github.com/delight-rpc/piscina
- Owner: delight-rpc
- License: mit
- Created: 2022-01-04T12:29:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-02-26T09:18:44.000Z (4 months ago)
- Last Synced: 2026-02-26T14:57:53.506Z (4 months ago)
- Topics: esm, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@delight-rpc/piscina
- Size: 1.62 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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]
```