src/streamingCalls/streamingApiCaller.ts
Properties |
Methods |
constructor(descriptor: StreamDescriptor)
|
||||||||
Defined in src/streamingCalls/streamingApiCaller.ts:48
|
||||||||
An API caller for methods of gRPC streaming.
Parameters :
|
descriptor |
Type : StreamDescriptor
|
Defined in src/streamingCalls/streamingApiCaller.ts:48
|
call | |||||||||||||||
call(apiCall: SimpleCallbackFunction, argument: literal type, settings: literal type, stream: StreamProxy)
|
|||||||||||||||
Defined in src/streamingCalls/streamingApiCaller.ts:92
|
|||||||||||||||
Parameters :
Returns :
void
|
fail | |||||||||
fail(stream: CancellableStream, err: Error)
|
|||||||||
Defined in src/streamingCalls/streamingApiCaller.ts:101
|
|||||||||
Parameters :
Returns :
void
|
init | |||||||||
init(settings: ApiCallerSettings, callback: APICallback)
|
|||||||||
Defined in src/streamingCalls/streamingApiCaller.ts:60
|
|||||||||
Parameters :
Returns :
StreamProxy
|
result | ||||||
result(stream: CancellableStream)
|
||||||
Defined in src/streamingCalls/streamingApiCaller.ts:105
|
||||||
Parameters :
Returns :
any
|
wrap | ||||||
wrap(func: GRPCCall)
|
||||||
Defined in src/streamingCalls/streamingApiCaller.ts:64
|
||||||
Parameters :
Returns :
GRPCCall
|
import {APICaller, ApiCallerSettings} from '../apiCaller';
import {
APICallback,
BiDiStreamingCall,
CancellableStream,
ClientStreamingCall,
GRPCCall,
ServerStreamingCall,
SimpleCallbackFunction,
} from '../apitypes';
import {warn} from '../warnings';
import {StreamDescriptor} from './streamDescriptor';
import {StreamProxy, StreamType} from './streaming';
export class StreamingApiCaller implements APICaller {
descriptor: StreamDescriptor;
/**
* An API caller for methods of gRPC streaming.
* @private
* @constructor
* @param {StreamDescriptor} descriptor - the descriptor of the method structure.
*/
constructor(descriptor: StreamDescriptor) {
this.descriptor = descriptor;
}
init(settings: ApiCallerSettings, callback: APICallback): StreamProxy {
return new StreamProxy(this.descriptor.type, callback);
}
wrap(func: GRPCCall): GRPCCall {
switch (this.descriptor.type) {
case StreamType.SERVER_STREAMING:
return (argument: {}, metadata: {}, options: {}) => {
return (func as ServerStreamingCall)(argument, metadata, options);
};
case StreamType.CLIENT_STREAMING:
return (
argument: {},
metadata: {},
options: {},
callback?: APICallback
) => {
return (func as ClientStreamingCall)(metadata, options, callback);
};
case StreamType.BIDI_STREAMING:
return (argument: {}, metadata: {}, options: {}) => {
return (func as BiDiStreamingCall)(metadata, options);
};
default:
warn(
'streaming_wrap_unknown_stream_type',
`Unknown stream type: ${this.descriptor.type}`
);
}
return func;
}
call(
apiCall: SimpleCallbackFunction,
argument: {},
settings: {},
stream: StreamProxy
) {
stream.setStream(apiCall, argument);
}
fail(stream: CancellableStream, err: Error) {
stream.emit('error', err);
}
result(stream: CancellableStream) {
return stream;
}
}