-
-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asynchronous app initialization and setup improvements #2500
Comments
Makes sense to me. To clarify, "using a service" means calling |
Correct. I updated the comment. We should be able to make the error message fairly descriptive. In the docs and generated apps we recommend getting the reference as late as possible (e.g. in a specific test instead of storing it early), |
Change to Now that code will become improper: app.configure(someConfigure);
app.configure(changeFooSetting);
console.log(app.settings.foo); The outputted result will depend on whenever Though I understand the need for a way to add async setup steps (wrote and use a simple utility of my own for that). I would recommend to introduce a new app method ( As for mandatory |
True, having different behavious based on what kind of function is passed (which you may not even know) makes it quite unpredictable. I'm not totally opposed to making |
I encountered a problem when trying to init Sequelize service.
|
Another thing about second idea (throwing on |
This has been addressed in #2585 as setup and teardown hooks |
I'm getting this error when trying to use a setup hook:
My code in app.ts
package.json
|
Ah, this only happens with Express apps because they are technically a function. Will be fixed in the next version via the linked pull request. |
Ok, I dont think I actually need express anyway as I'm running everything through socketio. I dont get the same error now when not using express, but it seems context.app is undefined in this case:
Also, if I'm passing any of the normal service hooks (before etc) in the same object as setup / teardown, I'm getting an invalid method error. |
This is also related to #1965 https://stackblitz.com/edit/feathers-vite-chat?file=src%2Fservices%2Findex.ts App.ts in the feathers-chat app is completely synchronous. The discoverability of this feature is not great. To improve the DX I think every service configure and every In general running code top level often pollutes globals and pseudo-globals, and as such should be avoided. Imagine copying App.ts renaming it and importing it to index.ts, next to the original app.ts. That would cause chaos. Yes I know you can alias package names in package.json, but even that would solve all the global conflicts server side. I just want to forget the ASYNC ALL THE THINGS... agreed? Async playground https://stackblitz.com/edit/feathers-async-playground?file=src%2Fservices%2Findex.ts |
PR #2255 adds an asyncronous
app.setup
andservice.setup
which can be used with new hooks. However, when working with @marshallswain we noticed that this is still not ideal when configuring your application. For example the MongoDB service needs the asynchronous model in theconfigure
function before itssetup
method is called. We are now looking at adding the following improvements:app.configure
should allowasync
functions. They will run in the orderapp.configure
is called and only when the previous function returns. If there is any asynchronousapp.configure
function,await app.setup()
orapp.listen()
must be called before any services (callingapp.service(name)
) can be used.setup
method,await app.setup()
orapp.listen()
must also be called before any services (callingapp.service(name)
) can be used.Both changes will work compatible with existing applications, specifically we wanted to avoid having to unnecessarily call
app.setup
on client side Feathers apps.Related to #509 and #853
The text was updated successfully, but these errors were encountered: