Introduce internal API call queuing mechanism #43

Merged
laurynas-karvelis merged 2 commits from master into master 2018-03-21 14:59:55 +00:00
Showing only changes of commit 465eca0c5e - Show all commits

View File

@ -66,17 +66,9 @@ const methods = ['getMe', 'sendMessage', 'forwardMessage', 'sendPhoto',
methods.forEach(method => { methods.forEach(method => {
API.prototype[method] = function (data) { //eslint-disable-line API.prototype[method] = function (data) { //eslint-disable-line
// implementation taken from https://github.com/yagop/node-telegram-bot-api/issues/192#issuecomment-249488807 // implementation taken from https://github.com/yagop/node-telegram-bot-api/issues/192#issuecomment-249488807
let resolve; return new Promise((resolve, reject) => {
let reject; this._queue.push({ method, data, resolve, reject });
process.nextTick(this._runQueue.bind(this));
const promise = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
}); });
this._queue.push({ method, data, resolve, reject });
process.nextTick(this._runQueue.bind(this));
return promise;
}; };
}); });