CoolFace
Apppublic

sanket3280/code-execution

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
progressEvents.js41 linesDownload Raw Back to utils
1/**2 * Server-side progress events utility3 * Emits events that can be picked up by WebSocket or other real-time mechanisms4 */5 6const EventEmitter = require('events');7 8class ProgressEventEmitter extends EventEmitter {}9const progressEmitter = new ProgressEventEmitter();10 11/**12 * Dispatch a progress update event13 * @param {Object} data - Event data (userId, problemId, solved, etc.)14 */15function dispatchProgressUpdate(data = {}) {16  console.log('📢 Progress event emitted:', data);17  progressEmitter.emit('progress:update', data);18  19  // Future: Emit via WebSocket to connected clients20  // io.to(data.userId).emit('progress:update', data);21}22 23/**24 * Listen for progress update events25 * @param {Function} callback - Callback function to handle the event26 * @returns {Function} Cleanup function to remove the listener27 */28function onProgressUpdate(callback) {29  progressEmitter.on('progress:update', callback);30  31  return () => {32    progressEmitter.off('progress:update', callback);33  };34}35 36module.exports = {37  dispatchProgressUpdate,38  onProgressUpdate,39  progressEmitter40};41