Files
infocom-systems-design/node_modules/langium/lib/node/worker-thread-async-parser.js
2025-10-03 22:27:28 +03:00

26 lines
1.2 KiB
JavaScript

/******************************************************************************
* Copyright 2023 TypeFox GmbH
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { ParserWorker } from '../parser/async-parser.js';
import { AbstractThreadedAsyncParser } from '../parser/async-parser.js';
import { Worker } from 'node:worker_threads';
export class WorkerThreadAsyncParser extends AbstractThreadedAsyncParser {
constructor(services, workerPath) {
super(services);
this.workerPath = workerPath;
}
createWorker() {
const path = typeof this.workerPath === 'function' ? this.workerPath() : this.workerPath;
const worker = new Worker(path);
const parserWorker = new WorkerThreadParserWorker(worker);
return parserWorker;
}
}
export class WorkerThreadParserWorker extends ParserWorker {
constructor(worker) {
super((message) => worker.postMessage(message), cb => worker.on('message', cb), cb => worker.on('error', cb), () => worker.terminate());
}
}
//# sourceMappingURL=worker-thread-async-parser.js.map