I am faced with a dataset consisting of the following information.
$scope.orders = [
{ material: 'A', quantity: 32, orderNumber: 'dummy'},
{ material: 'A', quantity: 65, orderNumber: 'dummy'},
{ material: 'A', quantity: 86, orderNumber: 'dummy'},
{ material: 'B', quantity: 45, orderNumber: 'dummy'},
{ material: 'B', quantity: 68, orderNumber: 'dummy'},
{ material: 'B', quantity: 15, orderNumber: 'dummy'},
{ material: 'C', quantity: 11, orderNumber: 'dummy'}
];
The challenge I am facing is processing (createOrder) these orders grouped by their respective materials. Once all the orders for a particular material have been processed, I need to trigger another function (materialRun) that executes a material run. This needs to be done sequentially as the backend system cannot handle parallel processing.
I envision the process to flow like this:
Material A: Order 1 -> Order 2 -> Order 3 -> Material Run
Once the Material Run for A is complete, move on to Material B
Material B: Order 1 -> Order 2 -> Order 3 -> Material Run
Once the Material Run for B is complete, proceed to Material C
...and so on
Furthermore, I require the output from each createOrder operation to update the orders list dynamically.
Currently, I am utilizing angular promises, but I am open to alternative approaches and suggestions. For reference, you can view an example in this fiddle: http://jsfiddle.net/a1sp0ye2/