Skip to content

Asynchronous Services: A Better Solution #6

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

Closed
freshgum-bubbles opened this issue Jun 20, 2023 · 2 comments
Closed

Asynchronous Services: A Better Solution #6

freshgum-bubbles opened this issue Jun 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@freshgum-bubbles
Copy link
Owner

In one of my applications, I have quite a few services which require explicit bootstrapping
before they can be safely used. In the case of that specific application, my solution boiled
down to a bootstrap (): Promise<void> method on services that needed to perform an
asynchronous action before it was usable.

As a result, a lot of services ended up like:

@Service([DatabaseService, WebServerService])
export class RootService {
  constructor (protected database: DatabaseService, protected webServer: WebServerService) {}

  async bootstrap () {
    await this.database.bootstrap();
    await this.webServer.bootstrap();
  }
}

There might be a way to solve this in DI.
While it looks like there was a proposal to add asynchronous services in TypeDI, it never emerged.
Additionally, it introduced a substantial amount of complexity into the API.

Another problem with that proposal was forcing all asynchronous services to be "ready"
before any other services could run. This, of course, has the side effect of slowing down the app.
Any important synchronous tasks can't be performed until everything is ready.
This would, of course, quickly bog the application down when a number of async services are introduced.

As a result, I'd like to create a different API that would handle this differently.
Namely, some of the design proposals for this API include:

  • Being able to import asynchronous services without "initialising" them.
  • Not having to wait for every asynchronous service to load before the app can start.
  • Being able to control the order of execution for asynchronous services.

Definitely food for thought.

@freshgum-bubbles freshgum-bubbles added the enhancement New feature or request label Jun 25, 2023
@freshgum-bubbles
Copy link
Owner Author

After careful consideration, the execution and orchestration of asynchronous services does not fall under the scope of TypeDI. These could be implemented by way of service buffering, which I am working on in a separate package.

@freshgum-bubbles freshgum-bubbles closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant