I am in need of wrapping an asynchronous function within a promise to ensure synchronous execution. The reason behind this is that I must obtain a result from the asynchronous function before proceeding with the program's execution.
Below is the relevant section of my code:
export abstract class OperationElement extends Sprite {
private imagePath;
abstract setPosition(mousePosition?, backgroundHeight?, backgroundWidth?) : void;
loadTexture(){
var _texture = PIXI.Texture.fromImage(this.imagePath);
this.texture = _texture;
console.log(this.height);
}
setImagePath(path : string){
this.imagePath = path;
}
}
The specific line causing the asynchronicity is
var _texture = PIXI.Texture.fromImage(this.imagePath);
Once the texture is loaded, I can acquire its height. However, I require the texture's height before advancing further in the program. How can I encapsulate this in a promise to achieve synchronous operation?
After browsing similar queries, I found that the most relevant ones had outdated and heavily downvoted answers, which makes me hesitant to follow those suggestions.