Web applications run asynchronously to improve the load times for web pages. What this means in practice is that you can't count on your script to run line by line.
Google Apps Script uses success handlers to pass information between functions, typically where one function fetches the data and the other does something with it.
For example, this code will first run the `processFile` function in `Code.gs` and, once the data are successfully returned, it will run the `fileUploaded` function in `JavaScript.html`.
```javascript title="Code.gs"
function processFile(fileData) {
return fileData;
}
```
```javascript title="JavaScript.html"
function uploadFile() {
var file = document.getElementById('file-input').files[0];
var reader = new FileReader();
reader.onload = function(e) {
google.script.run
.withSuccessHandler(fileUploaded)
.processFile(e.target.result)
}
}
function fileUploaded(status) {
document.getElementById('upload-form').innerHTML = status;
}
```
#expand Make this a read from spreadsheet call