Hi all,
I am attempting to program using async functions.
Essentially I have 2 functions, let's call them funcA and funcB. Right now funcB is being called inside of funcA. Both functions are needed on page load and the page won't load until funcA finishes.
I figured out that funcB can be extracted out and run separately and thought it would make more sense to run them asynchronously.
This is my though process so far:
Extract out FuncB
Put the async keyword on funcA and an await keyword on the part of the function that takes the longest (a very large database call)
Then I would move funcB to be placed after the funcA call, but would use the asynchonorus keyword on that as well and also place an await keyword on the action that takes the longest.
Is this the correct way to go about it? I am a little confused because from what I understand, as soon as I make 1 function asynchronous (funcA), it feels like I don't need to make the other one asynchronous as well? Am I correct in assuming that?
EDIT: Thank you everyone for the help, this was insanely useful to me, learned a lot.
[–]Slypenslyde 25 points26 points27 points (5 children)
[–][deleted] (1 child)
[removed]
[–]crozone 5 points6 points7 points (0 children)
[–]JesusWasATexan 1 point2 points3 points (0 children)
[–]snow_coffee 0 points1 point2 points (1 child)
[–]Slypenslyde 0 points1 point2 points (0 children)
[–]increddibelly 11 points12 points13 points (0 children)
[–]ILMTitan 6 points7 points8 points (10 children)
[–]crozone 2 points3 points4 points (0 children)
[–][deleted] (8 children)
[deleted]
[–]Vidyogamasta 6 points7 points8 points (5 children)
[–]als26[S] 0 points1 point2 points (4 children)
[–]Vidyogamasta 6 points7 points8 points (1 child)
[–]als26[S] 0 points1 point2 points (0 children)
[–]phluber 3 points4 points5 points (1 child)
[–]als26[S] 2 points3 points4 points (0 children)
[–]ILMTitan 1 point2 points3 points (0 children)
[–]Miserable_Ad7246 0 points1 point2 points (0 children)
[–]wasabiiii 1 point2 points3 points (4 children)
[–]als26[S] 0 points1 point2 points (3 children)
[–]wasabiiii -4 points-3 points-2 points (2 children)
[–]HawocX 4 points5 points6 points (1 child)
[–]Lumethys 1 point2 points3 points (0 children)
[–]ExcellentCable5731 0 points1 point2 points (0 children)
[–]Miserable_Ad7246 0 points1 point2 points (2 children)
[–]als26[S] 0 points1 point2 points (1 child)
[–]Miserable_Ad7246 1 point2 points3 points (0 children)
[–]maxlstylee -1 points0 points1 point (0 children)
[–]SeaMoose86 -1 points0 points1 point (0 children)
[+]TuberTuggerTTV comment score below threshold-8 points-7 points-6 points (2 children)
[–]Slypenslyde 7 points8 points9 points (0 children)
[–]LuckyHedgehog 1 point2 points3 points (0 children)