Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!