@delight-rpc/piscina
TypeScript icon, indicating that this package has built-in type declarations

0.5.5 • Public • Published

@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>

Readme

Keywords

none

Package Sidebar

Install

npm i @delight-rpc/piscina

Weekly Downloads

0

Version

0.5.5

License

MIT

Unpacked Size

10.6 kB

Total Files

15

Last publish

Collaborators

  • black_glory