File

src/bundlingCalls/bundleApiCaller.ts

Description

An implementation of APICaller for bundled calls. Uses BundleExecutor to do bundling.

Implements

APICaller

Index

Properties
Methods

Constructor

constructor(bundler: BundleExecutor)
Parameters :
Name Type Optional
bundler BundleExecutor No

Properties

bundler
Type : BundleExecutor

Methods

call
call(apiCall: SimpleCallbackFunction, argument: literal type, settings: CallSettings, status: OngoingCallPromise)
Parameters :
Name Type Optional
apiCall SimpleCallbackFunction No
argument literal type No
settings CallSettings No
status OngoingCallPromise No
Returns : void
fail
fail(canceller: OngoingCallPromise, err: GoogleError)
Parameters :
Name Type Optional
canceller OngoingCallPromise No
err GoogleError No
Returns : void
init
init(settings: ApiCallerSettings, callback?: APICallback)
Parameters :
Name Type Optional
settings ApiCallerSettings No
callback APICallback Yes
Returns : OngoingCallPromise | OngoingCall
result
result(canceller: OngoingCallPromise)
Parameters :
Name Type Optional
canceller OngoingCallPromise No
Returns : any
wrap
wrap(func: GRPCCall)
Parameters :
Name Type Optional
func GRPCCall No
Returns : GRPCCall
import {APICaller, ApiCallerSettings} from '../apiCaller';
import {APICallback, GRPCCall, SimpleCallbackFunction} from '../apitypes';
import {OngoingCall, OngoingCallPromise} from '../call';
import {CallSettings} from '../gax';
import {GoogleError} from '../googleError';

import {BundleExecutor} from './bundleExecutor';
import {TaskCallback} from './task';

/**
 * An implementation of APICaller for bundled calls.
 * Uses BundleExecutor to do bundling.
 */
export class BundleApiCaller implements APICaller {
  bundler: BundleExecutor;

  constructor(bundler: BundleExecutor) {
    this.bundler = bundler;
  }

  init(
    settings: ApiCallerSettings,
    callback?: APICallback
  ): OngoingCallPromise | OngoingCall {
    if (callback) {
      return new OngoingCall(callback);
    }
    return new OngoingCallPromise(settings.promise);
  }

  wrap(func: GRPCCall): GRPCCall {
    return func;
  }

  call(
    apiCall: SimpleCallbackFunction,
    argument: {},
    settings: CallSettings,
    status: OngoingCallPromise
  ) {
    if (!settings.isBundling) {
      throw new GoogleError('Bundling enabled with no isBundling!');
    }

    status.call((argument: {}, callback: TaskCallback) => {
      this.bundler.schedule(apiCall, argument, callback);
      return status;
    }, argument);
  }

  fail(canceller: OngoingCallPromise, err: GoogleError): void {
    canceller.callback!(err);
  }

  result(canceller: OngoingCallPromise) {
    return canceller.promise;
  }
}

result-matching ""

    No results matching ""