Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter about shard communication is unclear #1590

Open
Sheepolution opened this issue Nov 23, 2024 · 0 comments
Open

Chapter about shard communication is unclear #1590

Sheepolution opened this issue Nov 23, 2024 · 0 comments
Labels
t: request Suggestion to add new or change existing content

Comments

@Sheepolution
Copy link

Is your feature request related to a problem? Please describe.

It took me way too long to figure out that to communicate between shards (i.e. to have one shard communicate something to all other shards) is done by making use of manager.broadcast and process.on. This info is not available in the chapter about shard communication.

Describe the solution you'd like

Information or a code sample that roughly goes like this:

manager.spawn()
    .then(shards => {
        shards.forEach(shard => {
            shard.on('message', message => {
                manager.broadcast(message);
            });
        });
    })
    .catch(console.error);
process.on('message', (message: string) => {
    const data = JSON.parse(message);
    console.log(data.message);
});
process.send(JSON.stringify({ message: 'Hello World!'}));

And if I'm doing somehting wrong here, well I guess it's because the guide didn't teach me.

Describe alternatives you've considered

No response

Additional notes

No response

@Sheepolution Sheepolution added the t: request Suggestion to add new or change existing content label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: request Suggestion to add new or change existing content
Projects
None yet
Development

No branches or pull requests

1 participant