Async-Await or Promises with JavaScript functions [closed]











up vote
-12
down vote

favorite












I am building an application in Cordova using Firebase for the database.



I have been using promises to get information back from the database and it works great, but once I get that back I usually have a series of functions that I need to call to update everything.



For example,




  1. update local storage


  2. call variable from local storage


  3. reload page with updated storage information



I need to create/convert my JavaScript functions to be able to be called in succession.










share|improve this question















closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 at 22:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 6




    Can you edit the question title so it reflects the question's content?
    – McVenco
    Nov 12 at 21:24






  • 3




    Rewrite your title
    – George Jempty
    Nov 12 at 21:25










  • Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
    – Paulpro
    Nov 12 at 21:25






  • 1




    I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
    – Bergi
    Nov 12 at 21:28








  • 1




    Don't blame the language...blame the developer
    – charlietfl
    Nov 12 at 21:34















up vote
-12
down vote

favorite












I am building an application in Cordova using Firebase for the database.



I have been using promises to get information back from the database and it works great, but once I get that back I usually have a series of functions that I need to call to update everything.



For example,




  1. update local storage


  2. call variable from local storage


  3. reload page with updated storage information



I need to create/convert my JavaScript functions to be able to be called in succession.










share|improve this question















closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 at 22:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 6




    Can you edit the question title so it reflects the question's content?
    – McVenco
    Nov 12 at 21:24






  • 3




    Rewrite your title
    – George Jempty
    Nov 12 at 21:25










  • Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
    – Paulpro
    Nov 12 at 21:25






  • 1




    I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
    – Bergi
    Nov 12 at 21:28








  • 1




    Don't blame the language...blame the developer
    – charlietfl
    Nov 12 at 21:34













up vote
-12
down vote

favorite









up vote
-12
down vote

favorite











I am building an application in Cordova using Firebase for the database.



I have been using promises to get information back from the database and it works great, but once I get that back I usually have a series of functions that I need to call to update everything.



For example,




  1. update local storage


  2. call variable from local storage


  3. reload page with updated storage information



I need to create/convert my JavaScript functions to be able to be called in succession.










share|improve this question















I am building an application in Cordova using Firebase for the database.



I have been using promises to get information back from the database and it works great, but once I get that back I usually have a series of functions that I need to call to update everything.



For example,




  1. update local storage


  2. call variable from local storage


  3. reload page with updated storage information



I need to create/convert my JavaScript functions to be able to be called in succession.







javascript asynchronous promise async-await synchronous






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 21:49









Peter Mortensen

13.3k1983111




13.3k1983111










asked Nov 12 at 21:23









hefty_kat

2611




2611




closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 at 22:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 at 22:14


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 6




    Can you edit the question title so it reflects the question's content?
    – McVenco
    Nov 12 at 21:24






  • 3




    Rewrite your title
    – George Jempty
    Nov 12 at 21:25










  • Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
    – Paulpro
    Nov 12 at 21:25






  • 1




    I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
    – Bergi
    Nov 12 at 21:28








  • 1




    Don't blame the language...blame the developer
    – charlietfl
    Nov 12 at 21:34














  • 6




    Can you edit the question title so it reflects the question's content?
    – McVenco
    Nov 12 at 21:24






  • 3




    Rewrite your title
    – George Jempty
    Nov 12 at 21:25










  • Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
    – Paulpro
    Nov 12 at 21:25






  • 1




    I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
    – Bergi
    Nov 12 at 21:28








  • 1




    Don't blame the language...blame the developer
    – charlietfl
    Nov 12 at 21:34








6




6




Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 at 21:24




Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 at 21:24




3




3




Rewrite your title
– George Jempty
Nov 12 at 21:25




Rewrite your title
– George Jempty
Nov 12 at 21:25












Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
– Paulpro
Nov 12 at 21:25




Most likely your issues stem from updateCS() not returning a Promise (or even if it does, you're not using it)
– Paulpro
Nov 12 at 21:25




1




1




I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
– Bergi
Nov 12 at 21:28






I don't get your explanation why you "cant use a .then on this or place it in the .then above". Please try it and show us that code, the approach should work.
– Bergi
Nov 12 at 21:28






1




1




Don't blame the language...blame the developer
– charlietfl
Nov 12 at 21:34




Don't blame the language...blame the developer
– charlietfl
Nov 12 at 21:34












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.



For information on async-await check out Async/await.






share|improve this answer























  • Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
    – hefty_kat
    Nov 14 at 19:54










  • @hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
    – YulePale
    Nov 15 at 4:35


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.



For information on async-await check out Async/await.






share|improve this answer























  • Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
    – hefty_kat
    Nov 14 at 19:54










  • @hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
    – YulePale
    Nov 15 at 4:35















up vote
1
down vote



accepted










What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.



For information on async-await check out Async/await.






share|improve this answer























  • Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
    – hefty_kat
    Nov 14 at 19:54










  • @hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
    – YulePale
    Nov 15 at 4:35













up vote
1
down vote



accepted







up vote
1
down vote



accepted






What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.



For information on async-await check out Async/await.






share|improve this answer














What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.



For information on async-await check out Async/await.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 at 22:04









Peter Mortensen

13.3k1983111




13.3k1983111










answered Nov 12 at 22:03









YulePale

6918




6918












  • Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
    – hefty_kat
    Nov 14 at 19:54










  • @hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
    – YulePale
    Nov 15 at 4:35


















  • Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
    – hefty_kat
    Nov 14 at 19:54










  • @hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
    – YulePale
    Nov 15 at 4:35
















Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
– hefty_kat
Nov 14 at 19:54




Yeah, basically I have 8 functions that get called through out my app. Some of them need to be called in succession for the other ones to work. For example: update local storage variable needs to be done updating before i call that local storage variable to populate what is on the page. then once this is all done reload the page. I read that async stuff but without a more specific example it has always been hard for me to reverse engineer.
– hefty_kat
Nov 14 at 19:54












@hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
– YulePale
Nov 15 at 4:35




@hefty_kat try watching youtube videos, I find them easier to understand. Check out this video: youtube.com/watch?v=IGoAdn-e5II. The concept is well explained in a simple manner.
– YulePale
Nov 15 at 4:35



Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?