Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  105] [ 1]  / answers: 1 / hits: 17553  / 15 Years ago, mon, december 21, 2009, 12:00:00

if i fire up 2 functions like this:



prepare_data();
read_data();


then i guess they are running at the same time. but as you can see function two is depending on the first one, so how can i make the latter one run after the first one is completed?


More From » javascript

 Answers
14

Javascript, and most other languages, run code sequentially.



Therefore, they will not both run at the same time.



In fact, it is not possible to run two different pieces of Javascript code at the same time. However, in many other languages, it is possible using threads.



However, if they make AJAX calls, the corresponding server-side code called by both functions will run simultaneously.

To prevent that, you'll need to make the first function accept a callback parameter and pass it the second function.


[#98025] Thursday, December 17, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidan

Total Points: 72
Total Questions: 95
Total Answers: 121

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
aidan questions
Mon, Oct 11, 21, 00:00, 3 Years ago
Wed, Sep 29, 21, 00:00, 3 Years ago
Sun, Sep 5, 21, 00:00, 3 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;