Answer the question
In order to leave comments, you need to log in
How to correctly set recursion for map in nodejs?
There is this code:
longPoll(callback) {
let longPollMap = new Map();
this.arg = 0;
longPollMap.set('getLongPoll', () => {
this.callMethod('messages.getLongPollServer', {}, (body) => {
this.tempPoll = JSON.parse(body)['response'];
longPollMap.get('callLongPoll')();
});
});
longPollMap.set('callLongPoll', () => {
if(this.cap==false) {
request({
url: 'https://'+this.tempPoll['server'],
qs: {
act: 'a_check',
key: this.tempPoll['key'].substr(0, (this.tempPoll['key'].length - 10)),
ts: this.tempPoll['ts'],
wait: 25,
mode: 2
}
}, (error, response, body) => {
try {
body = JSON.parse(body);
if('failed' in body)
longPollMap.get('getLongPoll')();
else {
this.tempPoll['ts'] = body['ts'];
}
callback(body);
longPollMap.get('callLongPoll')();
} catch(e) {
console.log('LONGPOLL: '+e);
longPollMap.get('getLongPoll')();
}
});
} else longPollMap.get('callLongPoll')();
});
longPollMap.get('getLongPoll')();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question