Browse Source

Socket.IO : use socket.once instead of socket.on then socket.removeListener

master
KaKi87 2 years ago
parent
commit
9058c1e465
1 changed files with 1 additions and 2 deletions
  1. +1
    -2
      public/assets/js/index.js

+ 1
- 2
public/assets/js/index.js View File

@ -27,7 +27,7 @@ const search = (query, callback) => {
if(query.name === lastQuery)
query.number = 120;
socket.emit('search', query);
socket.on('res', res => {
socket.once('res', res => {
const r = [];
for(let i = 0; i < res.length; i++){
const _c = [];
@ -55,7 +55,6 @@ const search = (query, callback) => {
return socket.emit('search', query);
}
callback(r);
socket.removeListener('res');
lastQuery = query.name;
});
};


Loading…
Cancel
Save