From cd46d7bd203b69e6d163fd19e38600d9feae6e56 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 21 Nov 2023 16:20:01 +1100 Subject: Make lua db iterators async --- src/database/include/database.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/database/include') diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 972871db..63014bed 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -129,6 +129,8 @@ class Database { Database& operator=(const Database&) = delete; private: + friend class Iterator; + // Owned. Dumb pointers because destruction needs to be done in an explicit // order. leveldb::DB* db_; @@ -191,13 +193,19 @@ class Iterator { Iterator(std::weak_ptr, const IndexInfo&); Iterator(std::weak_ptr, const Continuation&); - auto Prev() -> std::optional; - auto Next() -> std::optional; + using Callback = std::function)>; + + auto Next(Callback) -> void; + auto Prev(Callback) -> void; private: + auto InvokeNull(Callback) -> void; + std::weak_ptr db_; - std::optional prev_pos_; + + std::mutex pos_mutex_; std::optional current_pos_; + std::optional prev_pos_; }; } // namespace database -- cgit v1.2.3