Check Broadcasters Are Properly Cancelled in Operators

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Some operators have the responsibility of managing multiple broadcasters and some very minor bugs can slip through if we don't take special care to cancel each of the broadcasters inside of that operator. In our scenario, this bug only shows up if you logout the values through an operator it doesn't even manifest inside of our game. But having a broadcaster that sticks around when you wanted it to cancel can lead to a lot of weird behaviors. So if your application starts acting up make sure to check in each of the operators that broadcasters are being canceled properly.

John Lindquist: [0:00] In the world of hidden bugs, there's one we're only going to find by logging out some values live. Let's set up a log operator. We'll take our broadcaster, our listener and set up our broadcaster, take the value. Then, we can console.log the value, and also listener of the value.

[0:18] With this operator, I'm going to drop it right here, so I can log what happens after the filter and before the done if, so hitting Save here. I'll guess this word and watch what happens in the log, so beveling. That was just fine, but now you'll see minims comes in.

[0:40] Once I type M, you'll see it's still comparing to beveling, which means that something again didn't get cancelled. Because we combined the two broadcasters here, my intuition says that it's somewhere in map broadcaster, where it sets up two broadcasters and would need to cancel both of them.

[0:58] If we check the map broadcaster, we see that we return the broadcaster, but we set up a new broadcaster but have no way of canceling it. We can take care of that by calling this a cancel and then tracking a newCancel, assigning our newCancel to the newBroadcaster and then returning a function that cancels. If newCancel exists, we will also call newCancel.

[1:31] Now, herewith, we're on our second word. You'll see sleepwalkers, and it should no longer be logging out herewith, only logging out sleepwalkers.

[1:43] While that bug didn't really cause as much of an impact of functionality of our game, you can imagine if this was a timer or something that this broadcaster could have easily run away from you, if your intention was to cancel and repeat it and it never got cancelled.

egghead
egghead
~ 30 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today