Hooks are synchronous, but plugins depend on asynchronous code
mhuggins opened this issue · 1 comments
Problem
I'm working on a project that's currently using apidoc in conjunction with apidoc-plugin-schema (as recommended by the apidoc readme). This works for older versions.
However, I'm working on upgrading a project to node 12. This involves updating several dependencies to newer versions, including json-schema-ref-parser, which is a dependency of apidoc-plugin-schema. The version of json-schema-ref-parser that's compatible with node 12 also now uses async/await instead of callback functions. Because of this, the logic currently built into apidoc-plugin-schema to wait for that callback to function no longer works, and we end up in an infinite loop waiting for something to process that's not being given an opportunity to process.
As far as I know, there's not a way for synchronous code to say "wait for this promise to function before returning". As such, there's not a way to use this plugin in node 12 and/or with the latest version of json-schema-ref-parser.
Suggested Solution
My suggestion is to have calls to applyHook be asynchronous, using await when calling app.hooks[name].func.apply(...). This would allow plugins to run asynchronous code while still returning a value after that async logic has completed.
Hello Matt,
I think you explained the issue clearly. Do you think it would be possible for you to propose a code change pertaining to this issue? I'm thinking something that would be backward compatible.