Don't create background queries for Results on threads without runloops
This commit is contained in:
parent
3e90c30571
commit
a95eb50915
|
@ -70,6 +70,10 @@ class BindingContext {
|
||||||
public:
|
public:
|
||||||
virtual ~BindingContext() = default;
|
virtual ~BindingContext() = default;
|
||||||
|
|
||||||
|
// If the user adds a notification handler to the Realm, will it ever
|
||||||
|
// actually be called?
|
||||||
|
virtual bool can_deliver_notifications() const noexcept { return true; }
|
||||||
|
|
||||||
// Called by the Realm when a write transaction is committed to the file by
|
// Called by the Realm when a write transaction is committed to the file by
|
||||||
// a different Realm instance (possibly in a different process)
|
// a different Realm instance (possibly in a different process)
|
||||||
virtual void changes_available() { }
|
virtual void changes_available() { }
|
||||||
|
|
|
@ -180,7 +180,7 @@ void Results::update_tableview()
|
||||||
if (!m_live) {
|
if (!m_live) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!m_realm->config().read_only && !m_realm->is_in_transaction() && !m_background_query) {
|
if (!m_background_query && !m_realm->is_in_transaction() && m_realm->can_deliver_notifications()) {
|
||||||
m_background_query = std::make_shared<_impl::AsyncQuery>(*this);
|
m_background_query = std::make_shared<_impl::AsyncQuery>(*this);
|
||||||
_impl::RealmCoordinator::register_query(m_background_query);
|
_impl::RealmCoordinator::register_query(m_background_query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,6 +411,19 @@ bool Realm::refresh()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Realm::can_deliver_notifications() const noexcept
|
||||||
|
{
|
||||||
|
if (m_config.read_only) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_binding_context && !m_binding_context->can_deliver_notifications()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Realm::get_schema_version(const realm::Realm::Config &config)
|
uint64_t Realm::get_schema_version(const realm::Realm::Config &config)
|
||||||
{
|
{
|
||||||
auto coordinator = RealmCoordinator::get_existing_coordinator(config.path);
|
auto coordinator = RealmCoordinator::get_existing_coordinator(config.path);
|
||||||
|
|
|
@ -107,6 +107,8 @@ namespace realm {
|
||||||
void verify_thread() const;
|
void verify_thread() const;
|
||||||
void verify_in_write() const;
|
void verify_in_write() const;
|
||||||
|
|
||||||
|
bool can_deliver_notifications() const noexcept;
|
||||||
|
|
||||||
// Close this Realm and remove it from the cache. Continuing to use a
|
// Close this Realm and remove it from the cache. Continuing to use a
|
||||||
// Realm after closing it will produce undefined behavior.
|
// Realm after closing it will produce undefined behavior.
|
||||||
void close();
|
void close();
|
||||||
|
|
Loading…
Reference in New Issue