2.0.11 • Published 2 months ago

nice-grpc-client-middleware-deadline v2.0.11

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

nice-grpc-client-middleware-deadline npm version

Client middleware for nice-grpc that adds support for setting deadline for a call, after which the call will get cancelled, and a ClientError with status code DEADLINE_EXCEEDED will be thrown.

Installation

npm install nice-grpc-client-middleware-deadline

Usage

import {
  createClientFactory,
  createChannel,
  ClientError,
  Status,
} from 'nice-grpc';
import {deadlineMiddleware} from 'nice-grpc-client-middleware-deadline';
import {addSeconds} from 'date-fns';

const clientFactory = createClientFactory().use(deadlineMiddleware);

const channel = createChannel(address);
const client = clientFactory.create(ExampleService, channel);

try {
  const response = await client.exampleMethod(request, {
    deadline: addSeconds(new Date(), 15),
  });
} catch (error: unknown) {
  if (error instanceof ClientError && error.code === Status.DEADLINE_EXCEEDED) {
    // timed out
  } else {
    throw error;
  }
}

Alternatively, you can specify deadline as a relative offset in milliseconds:

import ms from 'ms';

const response = await client.exampleMethod(request, {
  deadline: ms('15s'),
});
2.0.11

2 months ago

2.0.9

7 months ago

2.0.10

7 months ago

2.0.8

7 months ago

2.0.7

10 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.1

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.11

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.10

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago