mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
14 lines
510 B
TypeScript
14 lines
510 B
TypeScript
import { GatewayManager } from './gatewayManager.ts';
|
|
|
|
export function calculateWorkerId(manager: GatewayManager, shardId: number) {
|
|
// Ignore decimal numbers.
|
|
let workerId = Math.floor((shardId) / manager.shardsPerWorker);
|
|
// If the workerId overflows the maximal allowed workers we by default just use to last worker.
|
|
if (workerId >= manager.totalWorkers) {
|
|
// The Id of the last available worker is total -1
|
|
workerId = manager.totalWorkers - 1;
|
|
}
|
|
|
|
return workerId;
|
|
}
|