File

src/normalCalls/normalApiCaller.ts

Description

Creates an API caller for regular unary methods.

Implements

APICaller

Index

Methods

Methods

call
call(apiCall: SimpleCallbackFunction, argument: literal type, settings: literal type, canceller: OngoingCallPromise)
Parameters :
Name Type Optional
apiCall SimpleCallbackFunction No
argument literal type No
settings literal type No
canceller 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 {GoogleError} from '../googleError';

/**
 * Creates an API caller for regular unary methods.
 */
export class NormalApiCaller implements APICaller {
  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: {},
    canceller: OngoingCallPromise
  ): void {
    canceller.call(apiCall, argument);
  }

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

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

result-matching ""

    No results matching ""