class DatabaseConnection {
disconnect(): Promise<void> {
// ... disconnect
}
}
let node = makeRoot()
.add({
db: () => new DatabaseConnection(),
})
.dispose({
db: (containers) => containers.db.disconnect(),
})
// disposes of for all resources that have it defined
await node.dispose()
// under the hood (internals)
class Node {
async dispose(): Promise<void> {
await Promise.all(this.getDisposableResources().map((r) => r()))
}
}
Related to a conversation with @moltar https://github.com/molszanski/iti/issues/21
Propblem