Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
requestResponse(
payload: Payload,
): Single> {
const method: string = this._getMethod(payload);
const spanContext = deserializeTraceData(this._tracer, payload.metadata);
return this._getMetricsWrapper(false, method)(
this._getTracingWrapper(false, method)(spanContext)(
new Single(subscriber => {
const {data, metadata} = this._marshaller.unmarshall(payload);
return (
this._handler[method](data, metadata)
.map(this._marshaller.marshall)
// $FlowFixMe
.subscribe(subscriber)
);
}),
),
);
}
fireAndForget(payload: Payload): void {
const method: string = this._getMethod(payload);
const spanContext = deserializeTraceData(this._tracer, payload.metadata);
this._getMetricsWrapper(false, method)(
new Single(subscriber => {
this._getTracingWrapper(false, method)(spanContext)(
new Single(innerSub => {
const {data, metadata} = this._marshaller.unmarshall(payload);
this._handler[method](data, metadata);
innerSub.onSubscribe();
innerSub.onComplete();
}).subscribe({
onSubscribe: () => {
subscriber.onSubscribe();
},
onComplete: () => {
subscriber.onComplete();
},
}),
);
}).subscribe(),
fireAndForget(method: string, payload: Payload): void {
const tracingMap = {};
this._getMetricsWrapper(false, method)(
new Single(subscriber => {
this._getTracingWrapper(false, method)(tracingMap)(
new Single(innerSub => {
const {data} = this._marshaller.marshall(payload);
const tracingMetadata = mapToBuffer(tracingMap);
const metadata = encodeMetadata(
this._service,
method,
tracingMetadata,
payload.metadata || Buffer.alloc(0),
);
this._socket.fireAndForget({data, metadata});
innerSub.onSubscribe();
innerSub.onComplete();
}),
).subscribe({
onSubscribe: () => {
new Single(subscriber => {
this._getTracingWrapper(false, method)(spanContext)(
new Single(innerSub => {
const {data, metadata} = this._marshaller.unmarshall(payload);
this._handler[method](data, metadata);
innerSub.onSubscribe();
innerSub.onComplete();
}).subscribe({
onSubscribe: () => {
subscriber.onSubscribe();
},
onComplete: () => {
subscriber.onComplete();
},
}),
);
}).subscribe(),
);
export const requestResponse = ({ data }, serviceCall, handler = singleHandler) => {
return new Single(handler.bind(null, serviceCall, data));
};
connect(): Single> {
invariant(
!this._connection,
'RpcClient: Unexpected call to connect(), already connected.',
);
this._connection = new Single(subscriber => {
const transport = this._config.transport;
let subscription;
transport.connectionStatus().subscribe({
onNext: status => {
if (status.kind === 'CONNECTED') {
subscription && subscription.cancel();
subscriber.onComplete(new RpcSocket(this._config, transport));
} else if (status.kind === 'ERROR') {
subscription && subscription.cancel();
subscriber.onError(status.error);
} else if (status.kind === 'CLOSED') {
subscription && subscription.cancel();
subscriber.onError(new Error('RpcClient: Connection closed.'));
}
},
onSubscribe: _subscription => {
export default function embedMetricsSingleSubscriber(
single: Single,
next: Counter,
complete: Counter,
error: Counter,
cancelled: Counter,
timer: Timer,
): Single {
return new Single(subscriber => {
const metricsSubscriber = new MetricsSingleSubscriber(
subscriber,
next,
complete,
error,
cancelled,
timer,
);
single.subscribe(metricsSubscriber);
});
}
requestResponse(
method: string,
payload: Payload,
): Single> {
const tracingMap = {};
return this._getMetricsWrapper(false, method)(
this._getTracingWrapper(false, method)(tracingMap)(
new Single(subscriber => {
const {data} = this._marshaller.marshall(payload);
const tracingMetadata = mapToBuffer(tracingMap);
const metadata = encodeMetadata(
this._service,
method,
tracingMetadata,
payload.metadata || Buffer.alloc(0),
);
this._socket
.requestResponse({data, metadata})
.map(this._marshaller.unmarshall)
.subscribe(subscriber);
}),
),
);
}
requestResponse(payload: Payload): Single> {
const leaseError = this._useLeaseOrError(this._requesterLeaseHandler);
if (leaseError) {
return Single.error(new Error(leaseError));
}
const streamId = this._getNextStreamId(this._receivers);
return new Single(subscriber => {
this._receivers.set(streamId, {
onComplete: emptyFunction,
onError: error => subscriber.onError(error),
onNext: data => subscriber.onComplete(data),
});
const data = this._serializers.data.serialize(payload.data);
const metadata = this._serializers.metadata.serialize(payload.metadata);
const frame = {
data,
flags: payload.metadata !== undefined ? FLAGS.METADATA : 0,
metadata,
streamId,
type: FRAME_TYPES.REQUEST_RESPONSE,
};
this._connection.sendOne(frame);
connect(): Single> {
invariant(
!this._connection,
'RSocketClient: Unexpected call to connect(), already connected.',
);
this._connection = new Single(subscriber => {
const transport = this._config.transport;
let subscription;
transport.connectionStatus().subscribe({
onNext: status => {
if (status.kind === 'CONNECTED') {
subscription && subscription.cancel();
subscriber.onComplete(
new RSocketClientSocket(this._config, transport),
);
} else if (status.kind === 'ERROR') {
subscription && subscription.cancel();
subscriber.onError(status.error);
} else if (status.kind === 'CLOSED') {
subscription && subscription.cancel();
subscriber.onError(new Error('RSocketClient: Connection closed.'));
}