如何执行多个Javascript函数异步? [英] How Can I Execute Multiple Javascript Functions Asynchronous?

查看:57
本文介绍了如何执行多个Javascript函数异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个功能,如下例。



函数CallAsysnc(){



FirstFun( ); //第一个功能

SecondFun(); //第二个函数

}



如果我运行此代码然后我们知道javascript在单个线程中运行但我需要异步调用。

甚至我如何调用js文件并行?或者如何使用async.js完成?



将非常感谢您的回复。

非常感谢!



问候

Gaurv

I have two functions as below example.

function CallAsysnc(){

FirstFun(); // 1st function
SecondFun(); //2nd function
}

if i run this code then as we know javascript run in a single thread but i need asynchronous call.
even how can i call js files parallel? or how could it be done using async.js?

will appreciate your response.
Many Thanks!

Regards
Gaurv

推荐答案

正如你所提到的,JavaScript是单线程的,没有真正的异步函数调用...但是你可以使用 setTimeout [ ^ ]运行功能而不等待其返回...
As you mentioned JavaScript is single threaded, and there is no real asynchronous function call in it...However you may use setTimeout[^] to run function without waiting to its return...


这个链接可以帮到你。



http:// www。 w3schools.com/tags/att_script_async.asp [ ^ ]
This link will help you.

http://www.w3schools.com/tags/att_script_async.asp[^]


您可以尝试网络工作者: https://developer.mozilla.org/en/docs/Web/Guide/Performance/Using_web_workers [ ^ ] - 我自己从未使用过它们,但它们可能就是您要找的东西。
You could try web workers: https://developer.mozilla.org/en/docs/Web/Guide/Performance/Using_web_workers[^] - I've never used them myself, but they might be what you are looking for.

这篇关于如何执行多个Javascript函数异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆