I am sending data from python Flask (as Server Sent Event) but cant return this data from the function.
if print to console.log it works but if try to return it it says undefined
 let eventSource = new EventSource("/listen");
      function getData() {
        eventSource.addEventListener("online", function (e) {
          data = JSON.parse(e.data);
          let station = data.station;
          let finalData = data.data;
          console.log(finalData);
        });
      }
getData();
finalData is what to return to use it in stream graphics so changing console.log(finalData to return finalData shows undefined in console
