Let me explain my question in a better way:
I am building a TwitterBot that creates random images and tweets them.
To do so, I have two functions in a NodeJS application, one called createImage
and another called tweetIt
createImage
creates a PNG file.
tweetIt
takes this image and, using the twitter API, tweets it.
So I have something like this:
function createImage(){
//creates an image and saves it on disk
}
function tweetIt(){
//takes the image from the disk and tweets it
}
I need to execute createImage()
before tweetIt()
, since the second function depends entirely on the result produced by the first.
createImage();
tweetIt();
But NodeJS executes them in parallel. How can I force one function to be completed before the execution of the second one? I tried some solutions I found here with callbacks and external packages but nothing worked. Someone here have any ideia of what I'm doing wrong? Thanks!