Context:  

I'm building a app that can plot graph structures in electron with react. My backend is some Matlab code that can perform analysis on the graph struct. I'm using flask as the middle man communicating between them.

In the GUI i have a button that should be able to load the data that is provided in a excel file to the GUI. This should be done by a post request that uses a matlab script to load the data from the excel file and then returns this to javascript.

I have tried using something like this:

```

fetch('http://localhost:5000/getGriddata', {
method : 'POST',
headers : {
'Content-Type' : 'application/json'
},

          body : JSON.stringify(fileObj.path)

      }).then(response => response.json())
      .then(data => setGriddata(data))
      .catch(error => console.log(error));

```

The problem is that this code won't wait for the flask function to be finished. The flask function takes about 10 seconds depending on the graph size. Therefor i want to make this call in sync with my javascript code so that after the request, i can assure that the new griddata is defined.

Question:  

Is there some way to ensure this when using fetch?  

Do i need to find a different way of connecting to flask, if so what would that be?