Use a callback to point out when the operation has finished.

This change will make more sense when we make the operation async.
Make the image generation asynchronous using libuv.