11/14/2024 - 16:15

Cleaning Up After Yourself

It’s com­mon to run into the prob­lem of resources and tasks hang­ing around after they need to. It’s easy to for­get to close a data­base con­nec­tion, or can­cel a timer, or stop an HTTP request that isn’t need­ed any more. This can cause all sorts of sub­tle prob­lems from hang­ing to leaks and beyond.

Let’s look at dif­fer­ent ways to avoid this prob­lem, includ­ing the new “using” state­ment and the resource man­age­ment tools that come with it, along­side exist­ing APIs. We’ll explore pat­terns that make it eas­i­er to man­age resources in the face of unex­pect­ed excep­tions, and how to diag­nose which resources aren’t being closed properly.

Learning objectives

To explore how we can manage the lifecycles of resources like databases and timers explicitly using existing tools, plus new features like the "using" statement, and the "Symbol.dispose" interface.

Level

Basic

Prior knowledge

Experience with NodeJS would be useful
Jonathan Frere is a software developer working mainly on web development projects. His favourite topics include Typescript, testing, and other ways of writing and maintaining software that works, works right, and works fast. Find him on Linkedin and in the Fediverse.