Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created June 24, 2017 06:27
Show Gist options
  • Save myndzi/a99efe6a5c2b47c9d256b31932802a04 to your computer and use it in GitHub Desktop.
Save myndzi/a99efe6a5c2b47c9d256b31932802a04 to your computer and use it in GitHub Desktop.
var queue = [],
output = [];
function add(args) {
queue.push(args);
}
function delay(n) {
return new Promise(function (resolve) {
setTimeout(resolve, n);
});
}
function process() {
if (queue.length === 0) { return; }
return callAc(queue.pop(), [
'FormattedID',
'Name',
'Children',
'Parent',
'TeamMembers'
]).then(function (result) {
result.Object.Results.forEach(function (item) {
output.push(item.Name);
queue = queue.concat(item.Children._ref.split('webservice/v2.0')[1]);
});
return delay(1);
}).then(process);
}
function callAc(ref, parameters) {
return restApi.get({
ref: ref,
fetch: parameters,
scope: {
workspace: '/workspace/XXXX'
},
requestOptions: {}
});
}
add('/Project/<some_project_id>/Children');
process().then(function () {
console.log(output);
});
@karthikeayan
Copy link

awesome..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment