| 133 | } |
| 134 | |
| 135 | void DBmemory::commit_db_txn() { |
| 136 | #ifdef __EMSCRIPTEN__ |
| 137 | if (async_op) { |
| 138 | std::cout << "DBmemory::commit_db_txn kv previous op pending" << std::endl; |
| 139 | return; // previous operation pending |
| 140 | } |
| 141 | std::string committed_state; |
| 142 | committed_state.reserve(test_get_approximate_size() * 4 / 3); |
| 143 | common::StringOutputStream stream(committed_state); |
| 144 | // std::cout << "DBmemory::commit_db_txn kv count=" << storage.size() << std::endl; |
| 145 | stream.write_varint(storage.size()); |
| 146 | for (const auto &item : storage) { |
| 147 | stream.write_varint(item.first.size()); |
| 148 | stream.write(item.first); |
| 149 | stream.write_varint(item.second.size()); |
| 150 | stream.write(item.second); |
| 151 | } |
| 152 | async_op = |
| 153 | std::make_unique<AsyncIndexDBOperation>(full_path, committed_state.data(), committed_state.size(), [=]() { |
| 154 | std::cout << "DBmemory::commit_db_txn async op finished" << std::endl; |
| 155 | async_op.reset(); |
| 156 | }); |
| 157 | #endif |
| 158 | } |
| 159 | |
| 160 | void DBmemory::put(const std::string &key, const common::BinaryArray &value, bool nooverwrite) { |
| 161 | auto res = storage.emplace(key, value); |