import {connected} from 'process'; import {RuntimeException} from '../exception'; import {OutputOptions} from './options'; import {OutputProducer} from './producer'; import {Snapshot} from '../snapshot'; export class InterprocessOutput implements OutputProducer { constructor(options: OutputOptions) {} initialize() { if (connected === false) { throw new RuntimeException('This application is not connected to a parent application and therefore cannot use the IPC functionality'); } } async write(snapshot: Snapshot): Promise { this.send(snapshot); } async exception(exception: Error & {originalStack?: string, zoneAwareStack?: string}) { this.send({ exception: { name: exception.name, message: exception.message, stack: exception.stack, originalStack: exception.originalStack, zoneAwareStack: exception.zoneAwareStack }}); } private send(message: T) { if (process.send == null) { throw new RuntimeException(`Process (${process.pid}) is not connected to a parent process`); } return Promise.resolve(process.send(message)); } }