0.5.5 • Published 5 months ago

@delight-rpc/piscina v0.5.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

5 months ago

0.5.5

5 months ago

0.5.3

5 months ago

0.5.2

11 months ago

0.5.0

1 year ago

0.5.1

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.2

2 years ago

0.3.3

2 years ago

0.3.0

2 years ago

0.3.1

2 years ago

0.2.3

2 years ago

0.2.1

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago