Skip to content

Instantly share code, notes, and snippets.

@hairyhenderson
Last active August 30, 2016 02:05
Show Gist options
  • Save hairyhenderson/09065f3ea5106de8483c92954074f2f6 to your computer and use it in GitHub Desktop.
Save hairyhenderson/09065f3ea5106de8483c92954074f2f6 to your computer and use it in GitHub Desktop.
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