Q:

Promise.all() and .then issue

I'm trying to do some stack operations in node.js
Basically i'm trying to get the code below working.  The problem is that the pop happens before the push and I get the "empty stack" error.  
const stack = new stack;

findAllOfA()
.then(allA => {                         //first then
  return Promise.all(allA.map(A => {
  stack.push(a);
  });
})
.then(() => {                           //second then
  var topA = stack.pop();
  //Do some things with topA
}

I think i'm supposed to return something from within the function in map but I dont know what to return to make sure the first then is fullfilled before second then is invoked. 
It is psudocode (real code is pretty cluttered)
Here comes the real code (beware)
const catStack = new dataStructures. Stack();
  let layer = 0;

  //Generic while promise function
  function promiseWhile(predicate, action) {
    console.log('in while');
    function loop() {
      if (! predicate) return;
      return Promise.resolve(action()).then(loop);
    }
    return Promise.resolve().then(loop);
  }

  categoryFacade.findAllMainCategories()
    .then((mainCategories) => {
      return Promise.all(mainCategories.map((mainCategory) => {
        console.log(JSON.stringify(mainCategory.name, null, 0));
        catStack.push(mainCategory);
        return mainCategory;
      }));
    })
  .then(promiseWhile(!catStack.empty(), function() {
    console.log('in action');
    let nextToProcess = catStack.pop();
    layer += 2;
    console.log(JSON.stringify(nextToProcess.name, null, layer));
    return categoryFacade.findAllChildrenOf(nextToProcess.name)
    .then(allChildren => Promise.all(allChildren.map((child) => {
      catStack.push(child);
      return child;
    })));
  }))

A:

Promise.all() accepts value or promises.  So you can just return a.
Is your actual code more complicated than the example you show? 
I don't see a need to do it with Promise.all()
findAllOfA().then(allA => {
  allA.map(stack.push)
}).then(() => {
  const topA = stack.pop()
})

// or
findAllOfA().then(allA => allA.shift()).then(topA => {...})

If your first then() involves some async function, you will have a promise object at hand for each entry in allA, you just need to return that promise for Promise.all() to wait for. 
EDIT: Your problem is that your promiseWhile() is executed at evaluation, not when the then() is called. 
All you need it .then(() => promiseWhile(...))

