提问人:Lewis Patterson 提问时间:11/17/2023 更新时间:11/17/2023 访问量:8
LocalForage 丢弃实例似乎没有做任何事情
LocalForage drop instance dosen't seem to do anything
问:
我正在将 localForage 用于离线地图存储,这些地图存在于地图中的各个区域,区域 ID 作为键,localForage 实例作为地图的值。当用户想要删除特定区域存储的数据时,会调用一种方法,尝试从地图中删除实例,然后将其从地图中删除,但由于某种原因,这实际上似乎没有做任何事情。
这是删除方法
spTiles 是在下载区域数据时创建并添加到地图中的实例的映射
public async deleteTilesForArea(areaId: number): Promise<boolean> {
const tileSet = spTiles.get(areaId);
const keyIter = spTiles.keys()
console.log("key loop")
for (let k of keyIter) {
console.log("Key: " + k)
}
console.log("Tile Set? : " + !!tileSet)
if(!!tileSet) {
try {
// Ensure any asynchronous operations are complete before deletion
await tileSet.ready();
console.log("Pre Delete Length: total: " + spTiles.size);
await tileSet.length().then(res => "Pre Delete Tile Length: " + res)
// Assuming dropInstance is an asynchronous operation, you might want to await it
await tileSet.dropInstance();
// Ensure that the instance is fully closed or cleaned up
await tileSet.clear();
await tileSet.length().then(res => "Post Delete Tile Length: " + res)
spTiles.delete(areaId);
console.log("Post Delete Length: " + spTiles.size);
return true;
} catch (error) {
console.error('Error deleting localforage instance:', error);
return false;
}
return true;
}
return false;
}
我尝试返回布尔值的可观察对象并订阅它,但这似乎没有改变任何事情
答: 暂无答案
评论