Closing

The one rule of closing what an owner opened: in reverse order of opening, every one even when another fails to close, the first failure thrown once all were tried with the later ones suppressed by it. The host closes the stores it opened by it, and a store the ports it opened.

Functions

Link copied to clipboard

Closes closeables, given in the order they were opened, in reverse, as the rule says.

Link copied to clipboard
fun <T> onFailure(closeables: Collection<AutoCloseable>, block: () -> T): T

What block gives; when it fails, closeables (those opened so far, in order) are closed (inReverse) and its failure thrown as it was, with any failure to close suppressed by it.