Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requestAnimationFrame #123

Open
xinglie opened this issue Oct 27, 2024 · 2 comments
Open

requestAnimationFrame #123

xinglie opened this issue Oct 27, 2024 · 2 comments

Comments

@xinglie
Copy link
Owner

xinglie commented Oct 27, 2024

let testSync = () => {
    let last;
    let raf = time => {
        if (last) {
            console.log(time - last);
        }
        last = time;
        requestAnimationFrame(raf);
    };
    requestAnimationFrame(raf);
}

testSync();



let testAsync = () => {
    let last;
    let raf = async time => {
        if (last) {
            let diff = time - last;
            if (diff <= 5) {
                console.log('diff', diff);
            }
        }
        last = time;
        await Promise.resolve();
        requestAnimationFrame(raf);
    };
    requestAnimationFrame(raf);
};

testAsync();

let testAsync2 = async () => {
    let last;
    let raf = time => {
        if (last) {
            console.log(time - last);
        }
        last = time;
    };
    requestAnimationFrame(raf);
    await Promise.resolve();
    requestAnimationFrame(raf);
};

testAsync2();

let testSync3 = () => {
    let {
        port1, port2
    } = new MessageChannel();
    let exec;
    port1.onmessage = () => {
        exec?.();
    };
    let last;
    let raf = time => {
        if (last) {
            console.log(time - last);
        }
        last = time;
        exec = () => {
            requestAnimationFrame(raf);
        };
        port2.postMessage(null);
    };
    requestAnimationFrame(raf);
}

testSync3();
@xinglie
Copy link
Owner Author

xinglie commented Nov 9, 2024

@xinglie
Copy link
Owner Author

xinglie commented Nov 11, 2024

whatwg/html#2569

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant