I understand the behavior of asynchronous nature however my other synchronous code depend on return value from the callback. How can i reformat the code to achieve that.
Module A
export function processData(callback){
var value = "TEST";
callback(value);
}
Module B
import { processData } from './A.js';
var resultValue = ''; /*global variable */
function dataFetcher(){
processData(getData);
// define callback
function getData(x){
console.log(" I got x : "+x); /* prints TEST */
sendData(x);
}
//called from callback function
function sendData(data){
resultValue = data;
}
}
console.log(" print resultValue : "+resultValue); /* prints empty string */
Thanks for your time and suggestions.