Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@ch1/rpc-worker

1.1.0 • Public • Published

CH1 RPC

CircleCI

This is not well maintained

This is not traditional RPC, but it is like it

Installation

yarn add @ch1/rpc-worker

Usage

Slightly easier API than in the raw @ch1/rpc

Main JS Script

import * as wrpc from '@ch1/rpc-worker';
 
const w = new Worker(TEST_FILE);
const rpc = wrpc.create({ worker: w });
 
rpc.ready
  .then(() => rpc.remote.foo())
  .then(result => {
    expect(result).toBe(7);
    done();
  })
  .catch(done);

Worker JS

import * as wrpc from '@ch1/rpc-worker';
 
wrpc.create(undefined, {
  foo: () => new Promise(resolve => resolve(7)),
});

Error Handling

  • Individual remote function calls handle their own errors through their own async interfaces
  • Global errors related specifically to the workers trigger onDestroy
  • Calling RPC<RemoteType>.destroy() will call terminate on the worker
import * as wrpc from '@ch1/rpc-worker';
 
const w = new Worker(TEST_FILE);
const rpc = wrpc.create({ worker: w });
 
rpc.ready
  .then(() => rpc.remote.foo())
  .then(result => {
    expect(result).toBe(7);
    done();
  })
  .catch(done);
 
// handle onDestroy here
rpc.onDestroy((reason?: string) => {
  // cleanup, restart, whatever
});

API

The worker extension is pretty much as described above. For more information on the RPC<RemoteType> object see the @ch1/rpc docs

License

LGPL

Install

npm i @ch1/rpc-worker

DownloadsWeekly Downloads

1

Version

1.1.0

License

LGPL-3.0

Unpacked Size

29.2 kB

Total Files

25

Last publish

Collaborators

  • avatar