refactor(ws): event layout (#10376)

* refactor(ws): event layout

BREAKING CHANGE: All events now emit shard id as its own param

* fix: worker event forwarding

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
DD
2024-07-24 21:40:34 +03:00
committed by GitHub
parent fcd35ea2e7
commit bf6761a44a
7 changed files with 137 additions and 134 deletions

View File

@@ -148,12 +148,11 @@ export class WorkerBootstrapper {
for (const shardId of this.data.shardIds) {
const shard = new WebSocketShard(new WorkerContextFetchingStrategy(this.data), shardId);
for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {
// @ts-expect-error: Event types incompatible
shard.on(event, (data) => {
shard.on(event, (...args) => {
const payload: WorkerReceivePayload = {
op: WorkerReceivePayloadOp.Event,
event,
data,
data: args,
shardId,
};
parentPort!.postMessage(payload);