JavaScript implements multithreaded Concurrent.Thread.js

Source: Internet
Author: User

In this project, because the front-end to detect the hardware load and identify, and then request the background to send data, and then return the corresponding configuration file! In this process, good time several seconds, seriously affect the experience effect, so in the online view of the program, the use of multi-threading to deal with, this effect significantly improved!

  In this synchronous detection process, the effect is a large number for the For loop (mimicking complex logic code operations), where the card is not causing other operations!

You can use this library first, test the following code to see the effect:

 1  <script>2  var  btn = Document.queryselector ('. clickbtn '  3  btn.addeventlistener (' click ', function   () { 4  alert (' How long will it take me to bounce out!!! ' 

Because while the click button is in front, the JavaScript implementation is placed in the JavaScript asynchronous event queue , so this time wait for the for loop to execute alert (1);

This time with this library effect:

11 <script src= "Concurrent.Thread.js" ></script>22 <script>33 Concurrent.Thread.create (function () {44varBTN = Document.queryselector ('. clickbtn '));55 Btn.addeventlistener (' click ',function () {66 alert (' How long will it take me to bounce out!!! ‘)77         });88 for(vari = 0; i < 99999; i++) {99Console.log (i);Ten10         } One11     }); A</script>

Click the button immediately and then react alert! This is where the Shanli of multithreading ...

This project, which is used primarily for the asynchronous communication provided by this library: Concurrent.thread provides a custom communication library that uses JavaScript to implement asynchronous communication, which is designed to allow other threads to run when a thread waits for a response from the server. This communication is in stock at Concurrent.Thread.Http.

Refer to the tutorial for the following usage: Demo Get method

< script type= "Text/javascript" src= "Concurrent.Thread.js" ></script>
< script type= "Text/x-script.multithreaded-js" >
var req = Concurrent.Thread.Http.get (URL, ["Accept", "*"]);
if (Req.status = = 200) {
alert (Req.responsetext);
} else {
alert (Req.statustext);
}
</script>

For more detailed usage, you can view more information on the Internet to understand the charm of this library!

JavaScript implements multithreaded Concurrent.Thread.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.