-
Notifications
You must be signed in to change notification settings - Fork 69
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
Prevent race condition on creation of database #134
Comments
I am not sure if this would make a big difference, currently, the DB is created on the module initialization. What would change creating a method and calling it? I think to check if the DB is ready will still have to be done. |
It make a difference, in our case we want in some scenario delete the database on app starting. If your code is in a method which return a promise and that method is called into an APP_INITIALIZER provider in your module, it'll not create race condition. For the moment while our app is starting, your code start which create the db without store, our code do some stuff and then the rest of your code continue and try to create stores... |
@coolweb we´r facing the same issue |
Alright it makes sense, so I would think about passing a callback into the configuration to be called when it's done.. What do you think? |
A callback'll resolve the problem but I think the standard way in angular is to use the APP_INITIALIZER factory when we need to initialize async stuffs, in the forroot you initialize sync stuff like config values. I use APP_INITIALIZER in some apps for this kind of scenario, some info here https://www.tektutorialshub.com/angular/angular-how-to-use-app-initializer/ |
Just FYI since this is still open, to my knowledge, you can't use APP_INITIALIZER when the module is loaded lazily (and there is no MODULE_INITIALIZER equivalent yet), so a callback would be more universal |
Can this be related to #295 |
@all-contributors please add @coolweb for maintenance |
I've put up a pull request to add @coolweb! 🎉 |
The creation of the database is done in your forroot that call the ngx indexed db service constructor which create the db in asynchronous action. If some code try to access the database, the database might not be created.
A solution is to create a separate method to create the database with async return like promise and call this method in an APP_INITILAZER provider in your module.
The text was updated successfully, but these errors were encountered: