Waiting For Initilalization
When using persistent enmaps, it's very important to understand that it takes time to load the data from the database. Attempting to use the enmap before it's fully loaded can lead to errors, so we need to make sure it's ready before using it.
Using defer
To make sure that all your data is loaded before you start working, Enmap provides a handy property called defer
, which is a promise that is resolved once the provider is ready and all the data has been loaded into memory. There are a few ways to use defer
, since it's a promise.
For more information on async/await and promises, see My JavaScript Guide.
Checking for Ready
Enmap also provides a isReady
option that tells you if the database is loaded. You can use that however you want, though the preferred method is using defer
.
Last updated