-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
raidmulator: incomplete Promise check #5756
Comments
This is happening because the current zone when importing encounters from the indexedDB is within the dexie scope, so dexie's I believe the correct resolution for this would be to escape that zone after fetching the encounter from |
Oh, I see. Dexie overwrites the If I breakpoint the One nice thing about checking for I guess I see a couple of options:
(cc @valarnin) |
If you check the call stack, in all cases where it errors the top-level of the call stack will be in dexie's From the dexie
Basically, this code is calling the promise resolver while still within the transaction zone: cactbot/ui/raidboss/emulator/data/Persistor.ts Lines 61 to 67 in 31ef788
|
public async loadEncounter(id: number): Promise<Encounter | undefined> {
return new Promise<Encounter | undefined>((res) => {
let encounter: Encounter | undefined = undefined;
void this.transaction('readwrite', [this.encounters, this.encounterSummaries], async () => {
encounter = await this.encounters.get(id);
}).then(() => res(encounter));
});
} What about this? Based on https://dexie.org/docs/Dexie/Dexie.transaction(), it seems like the callback to transaction is in the zone, but if you defer until after the transaction is done then it will no longer be in the zone. |
Maybe this commented version will help with understanding? public async loadEncounter(id: number): Promise<Encounter | undefined> {
return new Promise<Encounter | undefined>((res) => {
// Start a new transaction with the `encounters` and `encounterSummaries` tables
void this.transaction('readwrite', [this.encounters, this.encounterSummaries],
// Running from within that transaction, so now `window.Promise` has been overwritten with `DexiePromise`
async () => {
// Call `resolve` handler with the result of the `get` for the encounter
// Any code directly resulting from this call is executed within the transaction's scope/zone
res(await this.encounters.get(id));
}
);
});
} I was thinking something even more simplified as such: public async loadEncounter(id: number): Promise<Encounter | undefined> {
let enc: Encounter | undefined;
await this.transaction('readwrite', [this.encounters, this.encounterSummaries], async () => {
enc = await this.encounters.get(id);
});
return enc;
} But I have no time right now to actually test any of these changes. |
I think we're on the same page. That seems like it works. I'll put up a PR. |
Description
When the type is 'StartsUsing', everything works fine, but when the type is something else, an error occurs. And if I add 'delaySeconds', there is no error. I don't quite understand.
I attempted to fix it in HERE, but I'm unsure why 'StartsUsing' is an exception.
Additional information
Realization
The text was updated successfully, but these errors were encountered: