Non-Blocking Operations: Multithread & Asynchronous loops! Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
2 posters

    Non-Blocking Operations: Multithread & Asynchronous loops!

    JScript
    JScript
    Forumember


    Male Posts : 741
    Reputation : 175
    Language : PT-BR, EN
    Location : Brazil

    Non-Blocking Operations: Multithread & Asynchronous loops! Empty Non-Blocking Operations: Multithread & Asynchronous loops!

    Post by JScript July 5th 2015, 12:21 am

    Hello guys!
    I took the liberty of creating this topic with the intention of together we can discuss on how to multi-task in JavaScript / jQuery (...)
    This is of paramount importance to the codes that make intensive use of loops such as our chatbox for example!
    So, here we go!


    Basic introduction:
    Spoiler:


    Loop: It can be defined as pieces of code that are repeated in a certain amount!

    1 - Synchronous Loops: They are most common when repetition is small they do not hinder the performance of other codes, but they contain a lot of repetitions, they can catch the browser interface and slow down the execution of other scripts! As the lines of the following codes to loop will only be executed after the loop ends.

    Running the code below on console and see that the first line to be executed is the console.log('start...');, then the synchronous "for loop" and then the last line console.log('End'); will be executed:
    Spoiler:

    Ok, so far so good, it was quick does not it?
    Now imagine our current model of the chat box, have you noticed that the messages "disappear" in an average of 15 minutes? If you leave the "archives" mode, you will see that the message list is great, but at the same time slow to appear completely!
    What is the reason? : Synchronous Loop!

    Or imagine a loop that has to look for something in an array of 10,000 entries !!! This locks out the browser interface and does not allow other code to run only when the loop ends...

    2 - Assynchronous Loops: They are a little more complex, but nothing that would prevent us from to use them, it makes the running in shared mode as "multi task"!!!
    Test the example below:
    Spoiler:

    Have you noticed that the lines console.log('start...'); and console.log('End'); were executed before the loop is finished?! This is due to asynchronous loop!!! There are several implementations on the web, I did and I use this because it is simple and works perfectly.


    Well, this is it guys, who want to contribute more information and codes, feel free!

    JS
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51515
    Reputation : 3519
    Language : English
    Location : United States

    Non-Blocking Operations: Multithread & Asynchronous loops! Empty Re: Non-Blocking Operations: Multithread & Asynchronous loops!

    Post by SLGray February 23rd 2017, 8:06 am

    This will no longer be supported by JScript: https://help.forumotion.com/t151137-in-memory-of-jscript-joao-carlos.



    Non-Blocking Operations: Multithread & Asynchronous loops! Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.