I want to call a AWS lambda function within which I am connecting to a Firebase database. The problem is that the handler executes before I get the needed data from Firebase.
A recipe to convert an asynchronous call into a synchronous one:
Let's assume the async call is called fooAsync(), and that you have some way to check a result condition when the operation is completed. You can introduce your own volatile boolean fooComplete to track this.
Then:
public void fooSyncWrapper() {
volatile boolean fooComplete = false;
Thread thread = new Thread() {
@Override
public void run() {
fooAsync();
while (!fooComplete) {
// busy wait on completion condition
fooComplete = checkIfComplete();
}
// task is completed, thread will join
}
};
thread.start();
thread.join();
}