worker_threads#workerData TypeScript Examples
The following examples show how to use
worker_threads#workerData.
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: healthWorker.ts From h1z1-server with GNU General Public License v3.0 | 6 votes |
export function healthThreadDecorator(target: Target) {
target.prototype._healthWorker = new Worker(`${__dirname}/healthWorker.js`, {
workerData: { threadToWatchPid: process.pid },
});
if (!process.env.VSCODE_DEBUG) {
target.prototype._healthWorker.on("message", () => {
target.prototype._healthWorker.postMessage(true);
});
}
}
Example #2
Source File: healthWorker.ts From h1z1-server with GNU General Public License v3.0 | 6 votes |
function checkHealth() {
const { threadToWatchPid } = workerData;
let healthTimeoutTimer: any;
const healthTimer = setTimeout(() => {
parentPort?.postMessage(true);
healthTimeoutTimer = setTimeout(() => {
process.kill(threadToWatchPid);
}, 25000);
}, 10000);
parentPort?.on("message", () => {
healthTimer.refresh();
clearTimeout(healthTimeoutTimer);
});
}
Example #3
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 #4
Source File: test-result-emitter-worker.ts From karma-test-explorer with MIT License | 6 votes |
initWorker = () => {
if (!parentPort || !workerData) {
return;
}
const messagePort = parentPort;
const { socketPort, pingTimeout, pingInterval }: TestResultEmitterWorkerData = workerData;
const socket = io('http://localhost:' + socketPort + '/', {
forceNew: true,
reconnection: true
});
const socketOptions = { pingTimeout, pingInterval };
Object.assign(socket, socketOptions);
messagePort.on('message', (event: KarmaEvent) => {
socket.emit(event.name, event);
});
}
Example #5
Source File: httpServer.ts From h1z1-server with GNU General Public License v3.0 | 5 votes |
{ MONGO_URL, SERVER_PORT } = workerData
Example #6
Source File: dynamicWeather.ts From h1z1-server with GNU General Public License v3.0 | 5 votes |
{ startTime, timeMultiplier } = workerData
Example #7
Source File: dynamicWeather.ts From h1z1-server with GNU General Public License v3.0 | 5 votes |
{ serverTime } = workerData
Example #8
Source File: worker.ts From scrape-yt with MIT License | 5 votes |
data = workerData
Example #9
Source File: indexer_worker.ts From aurora-relayer with Creative Commons Zero v1.0 Universal | 5 votes |
main(parentPort!, workerData as WorkerData);
Example #10
Source File: auth-redirect-server.ts From relate with GNU General Public License v3.0 | 5 votes |
server.listen({ host: workerData.host, port: workerData.port, });
Example #11
Source File: deserializer.ts From eosio-contract-api with GNU Affero General Public License v3.0 | 5 votes |
args: {abi: string} = workerData
Example #12
Source File: neovim-api.ts From uivonim with GNU Affero General Public License v3.0 | 5 votes |
nvimInstance = neovim.attach({ socket: workerData.nvimPath })
Example #13
Source File: minion.ts From serum-vial with Mozilla Public License 2.0 | 5 votes |
{ port, nodeEndpoint, markets, minionNumber } = workerData as {
port: number
nodeEndpoint: string
markets: SerumMarket[]
minionNumber: number
}
Example #14
Source File: serum_producer.ts From serum-vial with Mozilla Public License 2.0 | 5 votes |
serumProducer = new SerumProducer(workerData)