Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit f2b95ea

Browse files
committed
only callback when all calls return
1 parent c349f6b commit f2b95ea

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

initializers/v3client.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,16 @@ function getMemberGroups(connection, callback) {
216216
var memberGroups = [];
217217

218218
groupIds.forEach(function(groupId) {
219-
memberGroups.push(groupId);
220219
callService({
221220
url: v3url + 'groups/' + groupId + '/getParentGroup?oneLevel=false',
222221
method: 'GET',
223222
headers: {
224223
'Authorization': 'Bearer ' + token
225224
}
226225
}, function (err, body) {
226+
var idx = groupIds.indexOf(groupId);
227+
groupIds.splice(idx, 1);
228+
227229
if (err) {
228230
callback(err);
229231
} else {
@@ -234,12 +236,15 @@ function getMemberGroups(connection, callback) {
234236
console.log("member group ids: " + memberGroups);
235237
groupResponse = groupResponse.parentGroup;
236238
}
239+
240+
if (groupIds.length == 0) {
241+
console.log("member groups: " + memberGroups);
242+
callback(null, memberGroups);
243+
}
244+
237245
}
238246
})
239247
});
240-
241-
console.log("member groups: " + memberGroups);
242-
callback(null, memberGroups);
243248
}
244249
});
245250
});

0 commit comments

Comments
 (0)