| 25 | } |
| 26 | |
| 27 | DBmemory::DBmemory(OpenMode open_mode, const std::string &full_path, std::function<void()> &&o_h) |
| 28 | : full_path(full_path + ".memory"), o_handler(std::move(o_h)) { |
| 29 | #ifdef __EMSCRIPTEN__ |
| 30 | async_op = std::make_unique<AsyncIndexDBOperation>(full_path + ".memory", [=](const char *data, size_t size) { |
| 31 | // std::cout << "DBmemory::DBmemory async op" << size << std::endl; |
| 32 | if (data) { |
| 33 | std::cout << "fill_db " << size << std::endl; |
| 34 | common::MemoryInputStream stream(data, size); |
| 35 | size_t count = stream.read_varint<size_t>(); |
| 36 | std::cout << "fill_db count=" << count << std::endl; |
| 37 | std::string key; |
| 38 | common::BinaryArray value; |
| 39 | for (size_t i = 0; i != count; ++i) { |
| 40 | stream.read(key, stream.read_varint<size_t>()); |
| 41 | stream.read(value, stream.read_varint<size_t>()); |
| 42 | put(key, value, true); |
| 43 | } |
| 44 | std::cout << "fill_db finished" << std::endl; |
| 45 | } |
| 46 | async_op.reset(); |
| 47 | // std::cout << "before o_handler " << bool(o_handler) << std::endl; |
| 48 | o_handler(); |
| 49 | // std::cout << "after o_handler" << std::endl; |
| 50 | }); |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | DBmemory::~DBmemory() = default; |
| 55 | |