Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda