Skip to content

Commit

Permalink
fix(travis): avoid await in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Apr 9, 2018
1 parent d1c6bbc commit 790563d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"npm": "^5.5.1",
"npm-registry-client": "^8.5.0",
"npmlog": "^4.0.0",
"p-retry": "^1.0.0",
"parse-git-config": "^2.0.0",
"parse-github-repo-url": "^1.0.0",
"request": "^2.85.0",
Expand Down
15 changes: 5 additions & 10 deletions src/lib/travis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const {readFileSync, writeFileSync, accessSync} = require('fs');
const {join} = require('path');

const _ = require('lodash');
const {promisify, delay} = require('bluebird');
const {promisify} = require('bluebird');
const pRetry = require('p-retry');
const home = require('user-home');
const inquirer = require('inquirer');
const Travis = require('travis-ci');
Expand All @@ -29,10 +30,8 @@ const travisyml = {
};

async function isSyncing(travis) {
try {
const res = await promisify(travis.users.get.bind(travis))();
return _.get(res, 'user.is_syncing');
} catch (err) {}
const res = await pify(travis.users.get)();
return _.get(res, 'user.is_syncing');
}

async function syncTravis(travis) {
Expand All @@ -42,11 +41,7 @@ async function syncTravis(travis) {
if (err.message !== 'Sync already in progress. Try again later.') throw err;
}

/* eslint-disable no-await-in-loop */
while (await isSyncing(travis)) {
await delay(1000);
}
/* eslint-enable no-await-in-loop */
await pRetry(() => isSyncing(travis), {forever: true, minTimeout: 500, maxTimeout: 1000});
}

async function setEnvVar(travis, name, value) {
Expand Down

0 comments on commit 790563d

Please sign in to comment.