Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
create a simple waiting lobby

I am trying to create a waiting lobby in which when i fire a post request on the api it stores the data of the player and then wait for another player to join. when new player joins then it pairs the players and then returns them in the the response of both players. But problem i am facing is that when i am firing the request from the first player it is not waiting and instantly returning 404 error.

This is the code:-

this is the function that runs when the api is called:-

startGame(ctx) {
const player = ctx.request.body;
addToPlayers(player);
messageBus.on('match', (data) => {
  return data;
})}

this is the helper functions and emitters:-

var players = [];
var EventEmitter = require('events').EventEmitter;
var messageBus = new EventEmitter();
messageBus.setMaxListeners(100);

// function to manage players array
function addToPlayers(player) {
if (!player) {
return;
}
players.push(player)
if (players.length >= 2) {
const player1 = players.shift();
const player2 = players.shift();
messageBus.emit('match', {player1, player2});
}}

the post request consists of:- { "id": "1", "amount": "1000" }

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda