Для работы с обратным вызовом на основе вашего кода используйте рекурсию.
var entities = [];
function queryEntitiesSegmented(table, tableQuery, continuationToken){
tableService.queryEntities(table, tableQuery, continuationToken, (error, results)=> {
if (error) { console.log(error); }
else {
entities.push.apply(entities, results.entries);
if(results.continuationToken){
queryEntitiesSegmented(table, tableQuery, results.continuationToken);
}
else{
entities.forEach(entity=>{
// display each one
})
}
}
});
}
queryEntitiesSegmented(table, tableQuery, null);
Другой выбор - асинхронный и ожидающий.
const queryEntitiesSegmented = async(table, tableQuery, continuationToken)=>{
return new Promise((resolve,reject)=>{
tableService.queryEntities(table, tableQuery, continuationToken, (error, results)=> {
if (error) { reject(error); }
else { resolve(results); }
});
});
}
async function queryAllEntities(){
var tableQuery = new azure.TableQuery();
var table = 'tableName';
var continuationToken = null;
var entities = [];
do{
var results = await queryEntitiesSegmented(table, tableQuery, continuationToken);
continuationToken = results.continuationToken;
entities.push.apply(entities, results.entries);
}
while(continuationToken!=null);
return entities;
}
queryAllEntities().then(entities=>{
entities.forEach(entity=>{
//display each one
})
}).catch(error=>{ console.log(error); })