Loading topic
finally block. This chapter shows where that habit breaks down 2 min readSymbol.iterator, object literal methods, and Promises with async/await. The previous chapter showed how try/finally cleanup breaks down as code grows. Explicit resource management fixes that by giving cleanup a standard name, and that 2 min readasync/await, and well-known symbols such as Symbol.iterator. It covers the contract an object has to meet before using or await using can clean it up. The declarations themselves are covered in the next chapter2 min readlet and const, how try/finally behaves, and how an object implements Symbol.dispose, which the previous chapter covered. Here you will use that protocol through the using declaration, which runs cleanup for you when a block ends.2 min readusing declares a resource and how an object becomes disposable through Symbol.dispose. It also assumes you are comfortable with block scoping and try/finally. The examples use the openResource helper from earlier chapters, repeated here so that each 2 min readasync/await and promises work, and that you have read the earlier chapters on Symbol.asyncDispose and the plain using declaration. Here, await using carries the same scope-bound cleanup over to resources whose cleanup returns a promise.2 min readusing declarations work, how disposal order is decided, and how await using awaits cleanup. Here we look at what happens when the value on the right-hand side is not a normal disposable object.2 min readtry/catch/finally propagates errors, and how using disposes resources in reverse order when a block exits. Those were covered in earlier chapters.2 min readusing and await using dispose resources at block exit, how let/const block scoping works, and where await is legal. In this chapter, using refers to both forms unless the text says otherwise.2 min readusing disposes a resource at the end of its block, how disposal order works, and how for...of drives an iterator. Here the scope that ends is a single loop iteration.2 min readusing declaration, the order in which resources are disposed, and how SuppressedError reports failures during cleanup. A using declaration works well when you know at write time how many resources a block holds. It falls short when that number depends on runti2 min readawait using, DisposableStack and its use, adopt, defer, and move methods, and how SuppressedError reports cleanup failures. AsyncDisposableStack is the asynchronous version of DisposableStack. Use it when the group of resources you manage includes at l2 min readusing and await using, and the basic DisposableStack methods from earlier chapters. Here the focus moves from consuming resources to writing them. A well-designed disposable behaves predictably when it is disposed twice, when someo2 min readusing and await using syntax, the disposable protocol, and DisposableStack from earlier chapters. You should also be comfortable editing a tsconfig.json or a Babel config file. The question here is practical: how do you ship code that uses explicit r2 min read