Delay controller response until external data resolved from websocket

System Information
  • Strapi Version: 3.5.4
  • Operating System: MacOS
  • Database: Postgres
  • Node Version: 14.15.0
  • NPM Version: 7.11.1
  • Yarn Version: 1.22.10

Hello, Is there any way to delay the ctx response in controller until I get external data?
my code looks like this:

module.exports = {
  async find(ctx) {
    const socket = await new WebSocket(
      "wss://localhost:3030/socket.io/websocket"
    );
    socket.on("open", function () {
      console.log("connection opened");
      createSession();
    });
    socket.on("message", async function incoming(data) {
      ctx.body = data;
      console.log(data);
    });
  },
};

The console logs the data after the response of ctx resolved.
response:

[]
console returns the data after the response resolved:

[{userId....}......]