We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Publisher

In this course, we'll be building out components of "Peril" - a make-believe clone of the classic game "Risk". The only difference is that it's online and real-time!

Pub/Sub (publish/subscribe) systems are particularly useful when many events are happening in real-time and disparate parts of the system need to react to those events.

Assignment

While Pub/Sub is an architecture that often refers to messages being sent between programs, or sometimes even between machines on a network, let's start with a simple pub/sub system that runs in a single program.

In "Peril", users control armies, represented as a slice of pieces: []piece. When a piece moves to a location that contains a piece owned by another player, a battle occurs. Whenever a player makes a "move", we need to publish a message telling the game that a move has occurred.

Read the doBattles function. Note that it's expecting messages to come in from the publishCh channel.

Complete the march method. It should publish a move message to the publishCh channel.