Async-Await or Promises with JavaScript functions [closed]
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,
update local storage
call variable from local storage
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
closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 '18 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.
|
show 7 more comments
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,
update local storage
call variable from local storage
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
closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 '18 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 '18 at 21:24
3
Rewrite your title
– George Jempty
Nov 12 '18 at 21:25
Most likely your issues stem fromupdateCS()
not returning a Promise (or even if it does, you're not using it)
– Paulpro
Nov 12 '18 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 '18 at 21:28
1
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34
|
show 7 more comments
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,
update local storage
call variable from local storage
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
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,
update local storage
call variable from local storage
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
javascript asynchronous promise async-await synchronous
edited Nov 18 '18 at 21:49
Peter Mortensen
13.5k1983111
13.5k1983111
asked Nov 12 '18 at 21:23
hefty_kat
31112
31112
closed as too broad by George Jempty, JSteward, Dacre Denny, Jonas Wilms, david Nov 12 '18 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 '18 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 '18 at 21:24
3
Rewrite your title
– George Jempty
Nov 12 '18 at 21:25
Most likely your issues stem fromupdateCS()
not returning a Promise (or even if it does, you're not using it)
– Paulpro
Nov 12 '18 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 '18 at 21:28
1
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34
|
show 7 more comments
6
Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 '18 at 21:24
3
Rewrite your title
– George Jempty
Nov 12 '18 at 21:25
Most likely your issues stem fromupdateCS()
not returning a Promise (or even if it does, you're not using it)
– Paulpro
Nov 12 '18 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 '18 at 21:28
1
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34
6
6
Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 '18 at 21:24
Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 '18 at 21:24
3
3
Rewrite your title
– George Jempty
Nov 12 '18 at 21:25
Rewrite your title
– George Jempty
Nov 12 '18 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 '18 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 '18 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 '18 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 '18 at 21:28
1
1
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34
|
show 7 more comments
1 Answer
1
active
oldest
votes
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.
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 '18 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 '18 at 4:35
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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 '18 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 '18 at 4:35
add a comment |
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.
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 '18 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 '18 at 4:35
add a comment |
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.
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.
edited Nov 18 '18 at 22:04
Peter Mortensen
13.5k1983111
13.5k1983111
answered Nov 12 '18 at 22:03
YulePale
87111
87111
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 '18 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 '18 at 4:35
add a comment |
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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 4:35
add a comment |
6
Can you edit the question title so it reflects the question's content?
– McVenco
Nov 12 '18 at 21:24
3
Rewrite your title
– George Jempty
Nov 12 '18 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 '18 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 '18 at 21:28
1
Don't blame the language...blame the developer
– charlietfl
Nov 12 '18 at 21:34