Giter Site home page Giter Site logo

Comments (5)

latentflip avatar latentflip commented on July 23, 2024

f1 running before f4 is a necessary result of the delays that the app adds. We insert a 0.5 second delay between each step to allow you to see what's going on. If you increase the timeout of f1 you should see that it runs correctly.

This is equivalent in non delayed code to doing:

setTimeout(f1, 1);
// some stuff
setTimeout(f4, 0);

if you did that you'd see f1 before f4

from loupe.

latentflip avatar latentflip commented on July 23, 2024

The interval issue is most likely a bug with my instrumentation code, as it's effectively emulating the browser behaviour, rather than using it directly. I'm probably not running clearInterval properly at all I suspect.

from loupe.

asaadsaad avatar asaadsaad commented on July 23, 2024

Thank you very much! I did increase the timeout of f1 and it runs correctly.

I'll try to read the code sometime to figure out the interval issue!

from loupe.

buptyyf avatar buptyyf commented on July 23, 2024

In the video and experience, setTimeout() is a function of window and include in the Web Apis. And I have a question,when setTimout(()=>, time) is waiting during time,whether is controlled by a browser thread,otherwise which part know the time has finished and push in the queue?

from loupe.

silveoj avatar silveoj commented on July 23, 2024

Are you sure this loupe works correctly? I read explanation above but)

setTimeout(function timeout() {
    console.log("Timeout 1");
}, 3000); // or 300

setTimeout(function timeout() {
    console.log("Timeout 2");
}, 1000); // or 100

setTimeout(function timeout() {
    console.log("Timeout 3");
}, 2000); // or 200

setTimeout(function timeout() {
    console.log("Timeout 4");
}, 1000); // or 100

I always get this sequence in the browser (Chrome). It's logical and correctly:

Timeout 2
Timeout 4
Timeout 3
Timeout 1

3s 1s 2s 1s But here is not correctly:

Timeout 2
Timeout 1
Timeout 3
Timeout 4

0.3s 0.1s 0.2s 0.1s Here is different and not correctly:

Timeout 1
Timeout 2
Timeout 3
Timeout 4
  console.log('this is the start');

  setTimeout(function cb1() {
    console.log('this is a msg from callback 1');
  });

  console.log('this is just a message');

  setTimeout(function cb2() {
    console.log('this is a msg from callback 2');
  }, 0);

  console.log('this is the end');

Is it correctly works with setTimeout without 2nd argument (delay)? WebApis stores cb2() after finish.
If I have both setTimeout with 180 ms delay I will see both in WebApis after finish. But if 1st timeout has 180ms and 2nd timeout has 400ms I will see only cb1 in webApis. example

from loupe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.