Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript run two functions at the same time

/*
 * Running two functions at the same time can be
 * achieved using asynchronous functions.
 */
async function func1() {
	return 1;
}
async function func2() {
	return 2;
}
func1();
func2();
/*
 * In theory, the above two function calls are running
 * at the same time. In practive, however, they are
 * likely processed so fast that they are not
 * asnychronous.
 * To get the result of these functions, you need to
 * use the `then` method of the promise that is
 * returned. (You can also use the `catch` method in
 * the same way.)
 */
func1().then((res) => console.log(res)).catch((err) => console.error(err));
func2().then((res) => console.log(res)).catch((err) => console.error(err));
 
PREVIOUS NEXT
Tagged: #javascript #run #functions #time
ADD COMMENT
Topic
Name
6+1 =