cancellationtoken register

CancellationToken.Register(): The Observer Pattern You Already Know

Checking IsCancellationRequested works, but it only works if something is actively looking. A loop mid-await will notice eventually. But what about code that isn’t looping at all — a resource that just needs to clean itself up the moment cancellation happens, with nobody polling it? That’s what Register() is for. Instead of asking “has this […]

Read More
cancellationtoken

CancellationTokenSource in Unity: Why “Stop” Doesn’t Always Stop

Have you ever clicked Stop and watched your code keep running anyway? That’s not a bug. It’s a loop that was never given a way to check. It doesn’t ignore you on purpose — it simply never asked, so it never looks. Fixing this doesn’t require a redesign. It takes one object, threaded through the […]

Read More
ObserverPattern

When Should the View Just… React? Wiring Observer Pattern to a Health Bar

I almost didn’t need Observer pattern for this. A health bar is small — one int, one slider, one button. It would have been faster to just call view.SetSliderValue() directly from wherever health changes. That’s exactly the problem. “Wherever health changes” turns out to be more than one place the moment you add a second damage source, […]

Read More