Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Hooks are synchronous, but plugins depend on asynchronous code #95

Closed
mhuggins opened this issue Feb 27, 2020 · 1 comment
Closed

Hooks are synchronous, but plugins depend on asynchronous code #95

mhuggins opened this issue Feb 27, 2020 · 1 comment

Comments

@mhuggins
Copy link

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.

@NicolasCARPi
Copy link
Collaborator

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants