Code Monkey home page Code Monkey logo

Comments (3)

WarrenJones avatar WarrenJones commented on May 13, 2024

requestIdleCallback 就是在浏览器的空闲时段内调用的函数排队。deadline是为了保证cpu没有空闲的时间执行。document.visibilityState === 'hidden'是为了不在页面运作的时候执行

from nemetric.

vortesnail avatar vortesnail commented on May 13, 2024

@WarrenJones 但是我在你的代码中看到,虽然声明了全局的 requestIdleCallback,但是实际上并没有用到这个API,而是自己写的:

const requestIdleCallbackShim = (callback: any) => {
  const deadline = new IdleDealine(now());
  return setTimeout(() => callback(deadline), 0);
};

这样写难道是能模拟原生 requestIdleCallback 的效果吗?换个方式问就是,你自定义的这个垫片到底是怎么检测到 cpu 空闲的呢?

谢谢作者的耐心回答,我真的非常疑惑,就这部分代码读不懂~

from nemetric.

WarrenJones avatar WarrenJones commented on May 13, 2024

是的,模拟requestIdleCallback。然后不断轮询处理任务

from nemetric.

Related Issues (2)

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.