DELAPARRA
Index
Color
NL
Category: Programming paradigms

Subscription

Explained by Updated

What is Subscription?

Subscription: The act of "listening to" an observable. When you subscribe, you provide handlers for: next value, error, and completion. Don't forget to unsubscribe to avoid memory leaks. A subscription connects your code to an Observable. When you subscribe, you provide handlers for new values, errors and completion, and the stream starts delivering.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Subscription

How is Subscription used in practice?

Many streams never complete on their own, such as clicks, timers or WebSocket messages. Their subscriptions keep running until you unsubscribe, even after the component that created them is gone.

What should you keep in mind with Subscription?

Forgotten subscriptions are a classic source of memory leaks and of strange behaviour, such as an API being called twice because an old component still listens. Unsubscribe when a component is destroyed, or use helpers that do it for you, such as Angular's async pipe or the takeUntil pattern in RxJS. In Vue and React, the same applies to event listeners and intervals set up in effects or lifecycle hooks.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with S

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.