2020-11-10 00:30:27 +00:00
|
|
|
// @flow
|
2020-11-11 22:44:03 +00:00
|
|
|
import type { GrpcStatusObject, ServiceError } from './service-error';
|
2020-11-10 00:30:27 +00:00
|
|
|
import { GrpcResponseEventEnum } from '../../common/grpc-events';
|
|
|
|
|
|
|
|
interface IResponseCallbacks {
|
|
|
|
sendData(requestId: string, val: Object | undefined): void;
|
|
|
|
sendError(requestId: string, err: ServiceError): void;
|
2020-11-11 22:44:03 +00:00
|
|
|
sendStart(requestId: string): void;
|
|
|
|
sendEnd(requestId: string): void;
|
|
|
|
sendStatus(requestId: string, status: GrpcStatusObject): void;
|
2020-11-10 00:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class ResponseCallbacks implements IResponseCallbacks {
|
|
|
|
_event: IpcMainEvent = null;
|
|
|
|
|
|
|
|
constructor(e: IpcMainEvent) {
|
|
|
|
this._event = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendData(requestId, val) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.data, requestId, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendError(requestId, err) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.error, requestId, err);
|
|
|
|
}
|
2020-11-11 22:44:03 +00:00
|
|
|
|
|
|
|
sendStart(requestId) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.start, requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendEnd(requestId) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.end, requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendStatus(requestId, status) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.status, requestId, status);
|
|
|
|
}
|
2020-11-10 00:30:27 +00:00
|
|
|
}
|