I’m developing a chat app and using Realm as a local database to store messages and other data. I’m using the singleton realm provider pattern as outlined by Andrew Meyer in this meetup (https://youtu.be/6nqMCAR_v7U). When a user sends a message, the app receives the data via a websocket or other means (i.e. push notification) and writes it to the database. The idea is that if a message is written to the database and a user is viewing that particular list of messages, it should appear in the list, which it does. However, I’m occasionally seeing the error: “Error: Cannot create asynchronous query while in a write transaction”. I have researched this and I believe that it’s saying that while the database is being written to, a component can’t create a listener. Seems like some kind of race condition or something where the message is being written to the database while components (some with listeners) are being rendered.
Is this accurate? If so, what pattern should I be using to avoid this error?