nice-grpc-client-middleware-deadline
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.6 • Public • Published

    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;
      }
    }

    Keywords

    none

    Install

    npm i nice-grpc-client-middleware-deadline

    DownloadsWeekly Downloads

    211

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    7.92 kB

    Total Files

    7

    Last publish

    Collaborators

    • aikoven