I've been searching everywhere for info on promises or async/await, but they don't seem to work. I need to get the current date from a query function before I can use that date in subsequent functions. This is my best guess so far:

```
    // Retrieve current session date
    var currentDate;
    async function getMaxDate() {

        fetch(url).then((data) => {
            return data.json();
        }).then((json) => {

            // This is the date used in queries
            currentDate = json[obj].max.substr(0, 10);
            console.log(currentDate);

            return new Promise(resolve => {
                setTimeout(() => {
                    resolve(currentDate);
                }, 5000);
            });

        }).catch((e) => {
            console.error('There was an error:');
            console.log(e);
        });

    }

  async function getAllData() {
        try {
            currentDate = await getMaxDate();
            await getMarket(currentDate);
            console.log(currentDate);
        } catch (error) {
            console.log('An error occurred.');
        }
    }

    // This function is called when the document is first loaded
    $(function () {
        let promise = getAllData();
    });

```

But the behavior is the same with or without the promise/async/await - currentDate is still undefined until a few seconds later. I also tried calling this way:

```
    getAllData()
        .then(function (currentDate) {
            console.log(currentDate);
        });

```

Here currentDate is still undefined until a bit later. For additional clarification - getMaxDate does a fetch which may be just slow enough to cause this problem. Because later in that function, console.log(currentDate) does output the correct value. (currentDate is defined as a global variable.) But it's like my code is getting executed in random order...