/
eb
/
nodejs-screencast
Обзор
Документация
Войти
/
eb
/
nodejs-screencast
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
long-poll-chat/chat.js
27 строк
533 B
Ilya Kantor
better no-cache for long-poll-chat
09 сен 2013, 18:56
09 сен 2013, 18:56
014e43e
Код
Авторство
О чём код?
var clients = []; exports.subscribe = function(req, res) { console.log("subscribe"); res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); clients.push(res); res.on('close', function() { clients.splice(clients.indexOf(res), 1); }); }; exports.publish = function(message) { console.log("publish '%s'", message); clients.forEach(function(res) { console.log("send to client"); res.end(message); }); clients = []; }; setInterval(function() { console.log(clients.length); }, 5000);