worker_threads#MessagePort TypeScript Examples
The following examples show how to use
worker_threads#MessagePort.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: indexer_worker.ts From aurora-relayer with Creative Commons Zero v1.0 Universal | 6 votes |
async function main(parentPort: MessagePort, workerData: WorkerData) {
const { config, network, env } = workerData;
const engine = await Engine.connect(
{
network: network.id,
endpoint: config.endpoint,
contract: config.engine,
},
env
);
const indexer = new Indexer(config, network, engine);
await indexer.start();
setTimeout(function () {
indexer.insertNewHeads();
});
parentPort
.on('message', async (block: any) => {
parentPort.postMessage(true); // ack the request
const blockData = await indexer.indexBlock(block.id);
if (block.is_head) {
indexer.notifyNewHeads(block.id, blockData);
} else {
indexer.insert(blockData);
}
})
.on('close', () => {
return; // TODO?
});
}
Example #2
Source File: worker.ts From ironfish with Mozilla Public License 2.0 | 6 votes |
constructor(options: {
parent?: MessagePort
path?: string
maxJobs?: number
logger?: Logger
}) {
this.path = options.path ?? ''
this.maxJobs = options.maxJobs ?? 1
this.parent = options.parent ?? null
this.jobs = new Map<number, Job>()
this.started = true
this.logger = options.logger || createRootLogger()
if (options.parent) {
this.spawned()
} else {
this.spawn()
}
}
Example #3
Source File: saved-model.worker-thread.ts From node-question-answering with Apache License 2.0 | 5 votes |
loadPort: MessagePort
Example #4
Source File: saved-model.worker-thread.ts From node-question-answering with Apache License 2.0 | 5 votes |
inferencePort: MessagePort
Example #5
Source File: saved-model.worker.ts From node-question-answering with Apache License 2.0 | 5 votes |
private inferencePort: MessagePort;
Example #6
Source File: saved-model.worker.ts From node-question-answering with Apache License 2.0 | 5 votes |
private initPort: MessagePort;
Example #7
Source File: saved-model.worker.ts From node-question-answering with Apache License 2.0 | 5 votes |
private loadPort: MessagePort;
Example #8
Source File: worker.ts From ironfish with Mozilla Public License 2.0 | 5 votes |
parent: MessagePort | null = null