Skip to content

Commit

Permalink
optimize axios promise
Browse files Browse the repository at this point in the history
  • Loading branch information
HGlab01 committed Oct 6, 2024
1 parent 56bf042 commit de1e6de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ class Tado extends utils.Adapter {
* @param {any} data
*/
async apiCall(url, method = 'get', data = null) {
let promise;
try {
const waitingTime = 300; //time in ms to wait between calls
// check if other call is in progress and if yes loop and wait
Expand All @@ -1222,7 +1223,7 @@ class Tado extends utils.Adapter {
console.log(`Body "${JSON.stringify(data)}" for API call "${url}"`);
this.log.debug(`Body "${JSON.stringify(data)}" for API call "${url}"`);
}
return new Promise((resolve, reject) => {
promise = await new Promise((resolve, reject) => {
if (this.accessToken) {
this.refreshToken().then(() => {

Expand Down Expand Up @@ -1264,6 +1265,7 @@ class Tado extends utils.Adapter {
console.error(`Issue at apiCall: ${error}`);
this.errorHandling(error);
}
return promise;
}

/**
Expand Down

0 comments on commit de1e6de

Please sign in to comment.