- Jan 2, 2006
- 10,455
- 35
- 91
I've got three lines of code that must run sequentially:
1. I grab all the form inputs using jQuery (OrderFormContents) and put the results into an object (ShoppingCartObject).
2. I then take the ShoppingCartObject and use that to calculate the total price of all items. After the total price is calculated, I add the total price into the ShoppingCartObject (so the function takes ShoppingCartObject as an arguments and updates ShoppingCartObject with the total price).
3. After the ShoppingCartObject is complete, I sync it to a MongoDB collection.
I tried reading on Promises but I'm afraid I can't quite figure out how to implement them. All I want is to have this code run sequentially. Could anyone demonstrate?
I've using MeteorJS, so it's built on top of Node, if that changes anything.
Code:
1. buildShoppingCartObject(OrderFormContents); // returns ShoppingCartObject
2. getTotalPriceOfSelectedItems(ShoppingCartObject); // returns an updated ShoppingCartObject
3. syncShoppingCartObjectToCollection(ShoppingCartObject);
1. I grab all the form inputs using jQuery (OrderFormContents) and put the results into an object (ShoppingCartObject).
2. I then take the ShoppingCartObject and use that to calculate the total price of all items. After the total price is calculated, I add the total price into the ShoppingCartObject (so the function takes ShoppingCartObject as an arguments and updates ShoppingCartObject with the total price).
3. After the ShoppingCartObject is complete, I sync it to a MongoDB collection.
I tried reading on Promises but I'm afraid I can't quite figure out how to implement them. All I want is to have this code run sequentially. Could anyone demonstrate?
I've using MeteorJS, so it's built on top of Node, if that changes anything.