MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / loadAsync

Method loadAsync

Source/Cache/XmlItemCache.h:67–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 }
66 }
67 void loadAsync(String filename, const std::function<void(T* item)>& handler) {
68 std::string fullPath = SharedContent.getFullPath(filename);
69 auto it = _dict.find(fullPath);
70 if (it != _dict.end()) {
71 handler(it->second);
72 } else {
73 std::string file(filename.toString());
74 SharedContent.loadAsyncUnsafe(file, [this, file, handler](uint8_t* data, int64_t size) {
75 if (data) {
76 auto parser = prepareParser(file);
77 SharedAsyncThread.run(
78 [this, file, parser, data, size]() {
79 OwnArray<uint8_t> dataOwner = MakeOwnArray(data);
80 T* result;
81 try {
82 parser->parse(r_cast<char*>(data), s_cast<int>(size));
83 result = parser->getItem();
84 } catch (rapidxml::parse_error error) {
85 Error("xml parse error: {}, at: {}", error.what(), error.where<char>() - r_cast<const char*>(data));
86 }
87 return Values::alloc(result);
88 },
89 [this, handler, file](Own<Values> values) {
90 T* item;
91 values->get(item);
92 _dict[file] = item;
93 handler(item);
94 });
95 } else {
96 handler(nullptr);
97 }
98 });
99 }
100 }
101 T* update(String name, String content) {
102 std::string file = SharedContent.getFullPath(name);
103 std::string data(content.toString());

Callers

nothing calls this directly

Calls 14

handlerFunction · 0.85
MakeOwnArrayFunction · 0.85
getFullPathMethod · 0.80
loadAsyncUnsafeMethod · 0.80
getItemMethod · 0.80
findMethod · 0.65
toStringMethod · 0.65
runMethod · 0.65
parseMethod · 0.65
getMethod · 0.65
ErrorEnum · 0.50
allocFunction · 0.50

Tested by

no test coverage detected