Resubscribing to a Stream with Repeat

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 5 years ago

When you complete a stream, there’s no way to restart it, you must resubscribe. This lesson shows how repeat comes in handy to resubscribe after a stream has completed.

[00:00] You may have also noticed that if I start my game and it gets to the end, I got a score of zero and it completed. I try and start my game again, that nothing happens. Start doesn't work, half, none of these buttons work anymore. That's because this is done, the stream is complete, and you cannot restart a stream.

[00:19] What you can say is repeat. When I hit save now, and I come over here, I hit quarter, it gets to the end of my stream. I'll hit quarter again. It gets to the end again. What's happening is and you can tell is that it's getting that final score of zero and then it's resetting back to that initial count and then getting the score of zero and then resetting to the initial count.

[00:48] This stream is never completing. That's fine because it gets to the subscribe block and gives us our score which was zero. It re-subscribes, so it's like adding another subscription to our initial stream. It's even doing the reduce in everything, but it's never hitting this complete because it's re-subscribing to the same stream.

[01:11] Now, you'll want to be careful with repeat because if you put it somewhere like up here, it's never going to do anything after where you repeat from. The weird behavior you'll see now is if I hit quarter, you'll get to zero of the quarter. It's not getting down here and re-subscribing and giving us the final score or anything.

[01:30] You want to make sure you put the repeat usually right before the subscribe block so that it does everything and re-subscribes to where you want it to. We get the reduce. To show this a bit better, I'll just say score, X and then hit start. I'll say one, two, three and I got a score of one. I'll need to do a bit better. Hit start one, two, three. You can see that time I got a score of three and our game restarted.

egghead
egghead
~ just now

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