Last active
August 30, 2016 02:05
-
-
Save hairyhenderson/09065f3ea5106de8483c92954074f2f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const async = require('async') | |
function waitForUpdate (appId, updatedInitial) { | |
var updated = updatedInitial | |
return new Promise((resolve, reject) => { | |
async.whilst( | |
() => updated === updatedInitial, | |
(callback) => { | |
getLastUpdated(appId, (err, lastUpdated) => { | |
if (err) { | |
return callback(err) | |
} | |
updated = lastUpdated | |
callback(null, updated) | |
}) | |
}, | |
(err, result) => { | |
if (err) { | |
return reject(err) | |
} | |
resolve(result) | |
} | |
) | |
}) | |
} | |
function getLastUpdated (appId, callback) { | |
this.getCloudHubCookie().then((cookie) => { | |
let options = { | |
headers: { Cookie: `${cookie.name}=${cookie.value}` }, | |
json: true | |
} | |
request.get(`${this.browser.baseUrl}/api/v1/apps/${appId}`, options, (err, res, body) => { | |
if (err) { | |
return callback(err) | |
} | |
callback(null, body.lastUpdated) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment