| 147 | } |
| 148 | |
| 149 | void PersistentStore::scheduleSave(Function<void(Result<Void>)> completion) { |
| 150 | auto wasEmpty = _pendingSaves.empty(); |
| 151 | _pendingSaves.emplace_back(std::move(completion)); |
| 152 | if (wasEmpty) { |
| 153 | if (_disableBatchWrites) { |
| 154 | doSave(); |
| 155 | } else { |
| 156 | _dispatchQueue->asyncAfter([self = strongRef(this)]() { self->doSave(); }, |
| 157 | std::chrono::milliseconds(kPersistentStoreSaveDelayMs)); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void PersistentStore::doSave() { |
| 163 | Result<Void> result; |