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

feat(ScriptAPI): timeout & interval #5454

Open
wants to merge 5 commits into
base: nextgen
Choose a base branch
from

Conversation

MukjepScarlet
Copy link
Contributor

@MukjepScarlet MukjepScarlet commented Jan 26, 2025

Note: body of callback will be always executed on the main thread (render thread).
example:

const id = setTimeout(() => {
    Client.displayChatMessage("1111");
}, 5000);

clearTimeout(id);

Note: the Kotlin auto-generated FunctionN interfaces don't have @FunctionalInterface annotation, so it can't be cast by Polyglot.

@MukjepScarlet MukjepScarlet marked this pull request as ready for review January 26, 2025 15:29
Copy link
Contributor

@sqlerrorthing sqlerrorthing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@Tewxx
Copy link

Tewxx commented Feb 14, 2025

Vouch

Copy link
Member

@1zun4 1zun4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this is a very bad API feature to provide. We are using JS in a game environment, where we have functions run over and over, where unlike in a browser environment we would actually need timeout to e.g. wait X seconds after a button was pressed.

Because we have update functions here, people would accidentally use this function without remembering the consequences, which are that when they start a timeout, on the next tick another timeout will start, essentially stacking multiple timeouts and the only solution to this is to add another if check of a lock variable.

@sqlerrorthing
Copy link
Contributor

sqlerrorthing commented Feb 14, 2025

In my opinion this is a very bad API feature to provide. We are using JS in a game environment, where we have functions run over and over, where unlike in a browser environment we would actually need timeout to e.g. wait X seconds after a button was pressed.

Because we have update functions here, people would accidentally use this function without remembering the consequences, which are that when they start a timeout, on the next tick another timeout will start, essentially stacking multiple timeouts and the only solution to this is to add another if check of a lock variable.

add a sequence api? (like a sequence event handler)

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

Successfully merging this pull request may close these issues.

4 participants