Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disposing feature. addDisposer and disposerAll methods #26

Merged
merged 5 commits into from
Oct 7, 2022

Conversation

molszanski
Copy link
Owner

@molszanski molszanski commented Sep 17, 2022

Related to a conversation with @moltar
#21

Propblem

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()))
  }
}

@molszanski molszanski self-assigned this Sep 17, 2022
@molszanski molszanski changed the base branch from master to feature/add-destructuring September 17, 2022 17:43
@molszanski molszanski changed the title add dispose feature add disposing feature. addDisposer and disposerAll methods Sep 17, 2022
@molszanski molszanski merged commit 4cc3823 into feature/add-destructuring Oct 7, 2022
@molszanski molszanski deleted the feature/add-disposing branch October 7, 2022 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant