Skip to content

Chapter about shard communication is unclear #1590

Open
@Sheepolution

Description

@Sheepolution

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    t: requestSuggestion to add new or change existing content

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions