In some cases you need to make Async ‘code executor’.

 

Here is a simple example that uses the new image-js library to load an image (in an async way, no choice) and get the histogram from it. All the trick is that you can only set the variable out (here the histogram) after loading and processing the image.

 

Please take care than in the case of "Promise", the then should have as parameters TWO functions. When in case of success and one in case of error.

In this example even in case of an error we call the 'done' function.