Javascript, wait until images are loaded

Hi, i am working on a plugin for my game that automatically loads parallax images on map enter.

Because in big maps that is slow(1-3 seconds with strange screen effects) i want to show a 'loading image' over screen, then load all parallax images, and when everything is loaded remove the loading image from screen.

I'am using gameScreen.showPicture() to load all that images, but that runs in async, and the function returns before the image is loaded and visible on screen.

My question is: After calling gameScreen.showPicture() many times, how to check/wait until all images are loaded, before proceeding to next step?

Load "loading" image.
Wait for image load.
Load parallax image 1
Load parallax image 2
Load parallax image 3
Load parallax image 4
...
Load parallax image 32
Wait for all images
Hide "loading" image

Any help will be appreciated.
Hello!
You can use the ’script’ command and type in:

this.setWaitMode('image');

This will wait until all images in ImageManager ready, to run next command.
By the way, you can load pictures/paralaxes by using:

ImageManager.loadPicture('picture name in img/pictures/');
ImageManager.loadParallax('picture name in img/parallaxes/');

but of couse, showPicture will be fine!
Thanks @cji3bp62000, but i think that only works for commands in a event editor not in plain JS and i'am trying to do all
the work in the plugin side.

Calling this.setWaitMode("Image") automatically returns, also calling ImageManager.loadPicture() automatically returns.

I think maybe i can set this.setWaitMode() and then, re-run my plugin command playing with Game_Interpreter._idx, and doing all the work in 'steps' but i don't know if its a correct approach.
Last I checked you can easily chain addLoadListener() to loadPicture()., I could be wrong though.
Code:
ImageManager.loadPicture('picture.png').addLoadListener(bitmap => console.log('Bitmap Loaded!, bitmap)
Last I checked you can easily chain addLoadListener() to loadPicture()., I could be wrong though.
Code:
ImageManager.loadPicture('picture.png').addLoadListener(bitmap => console.log('Bitmap Loaded!, bitmap)
That works,
Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/javascript-wait-until-images-are-loaded.91660/