implemented ImageRef.waitFor()

This commit is contained in:
Hendrik Brummermann 2026-02-01 22:43:01 +01:00
parent afb06b8f97
commit 2bd16f0307
2 changed files with 13 additions and 4 deletions

View file

@ -21,6 +21,7 @@ export class ImageManager {
imageRef = new ImageRef(filename);
}
imageRef.use();
imageRef.load();
return imageRef;
}

View file

@ -13,12 +13,16 @@ import { stendhal } from "stendhal";
export class ImageRef {
image?: ImageBitmap;
refCount = 0;
lastFreed?: Date;
closed = false;
private refCount = 0;
private lastFreed?: Date;
private closed = false;
private loaded: Promise<ImageBitmap>;
private promiseResolve!: Function;
constructor(private filename: string) {
// empty
this.loaded = new Promise((resolve) => {
this.promiseResolve = resolve;
})
}
async load() {
@ -37,6 +41,7 @@ export class ImageRef {
return;
}
this.image = bitmap;
this.promiseResolve(bitmap);
}
/**
@ -69,4 +74,7 @@ export class ImageRef {
this.image = undefined;
}
async waitFor(): Promise<ImageBitmap> {
return this.loaded
}
}