fastify/avvio

Sync loading?

Uzlopak opened this issue ยท 7 comments

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

๐Ÿš€ Feature Proposal

Is there any way that I could propose a way to sync load plugins?
detecting the number of parameters of the pluign function (3 === callbackPlugin) or checking if the function is async (like I implemented it here should be a good enough to determine that an non async function with 2 parameters is a sync function?!

Maybe add symbol to check if the method is a sync Function so when we load the plugin we check if syncSymbolKey is true and load it sync instead of async?

Motivation

I want to load some specific plugins sync. now i have to await it to ensure it is loaded when I want to add the next plugin

Example

No response

Maybe there could be a separate method for that? Polymorphic magic adds significant complexity.

Creating a registerSync method in fastify feels kind lf odd.

What's odd about it, if behaviour is different?

Before that gets approved i assume an await is easier.

now i have to await it to ensure it is loaded when I want to add the next plugin

What's the problem you see in doing this?

"easier" is a subjective concept. The fact that it requires less code doesn't mean that it doesn't also increase cognitive complexity of said code. If there are two wildly different branches possible for very similar code, that reduces predictability of the said code.

It's impossible to load a plugin synchronously because there can be more than one asynchronous plugin being loaded.