fastify/avvio

Support await for `after` method

allevo opened this issue · 2 comments

Hi!
currently the ready method support the promises. So you can write

await avvioInstance.ready()
console.log('UP!')

It can be useful for after method too.

await avvioInstance.use(...).after()
await Promise.all([
  avvioInstance.use(...).after(),
  avvioInstance.use(...).after()
])
...
await avvioInstance.ready()
console.log('UP!')

Unfortunately that will not be feasible:

avvio.use(async something (i, opts) {
  await this.after(func)
  // this line will never be executed
})

While await avvio.ready() make sense because it's top-level only.

BTW, there is no need to await on .use().

We already discussed about that in #36.
You will run in a race condition, because after internally uses use :)