Add support for Services that need a async setup
See original GitHub issueThere are several examples where a Service needs a async step to be completely initialised. For example database connections:
https://github.com/L2jLiga/fastify-decorators/blob/v3/examples/typeorm/src/services/connection.service.ts https://github.com/L2jLiga/fastify-decorators/blob/v3/examples/typeorm/src/facades/message.facade.ts
A basic way to do this would be to look for a promise property named ready (or even better, a symbol to avoid collisions) on a service and await on them before starting the server.
A more advanced way, which can be done afterwards, would be a decorator on an async function but a Service may require other Services have inited so this is more tricky and require a big time investment.
The good news is the basic way does not conflict with the more advanced way so it can be built separately and be supported independently. Also the init dependency graph can be manually solved with the basic version by awaiting the other services to init.
What do you think? I would be happy to do a PR for the basic one, as I need it 😄
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)

Top Related StackOverflow Question
Had some personal issues, sorry. It’s almost done and I think I have time to work on it tomorrow. Sorry it took so long.
Had some problems during the weekend and didn’t get to finish. Gona try and finish these days.