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

Possible cancel of command promises #940

Open
jcubic opened this issue May 3, 2024 · 3 comments
Open

Possible cancel of command promises #940

jcubic opened this issue May 3, 2024 · 3 comments
Labels

Comments

@jcubic
Copy link
Owner

jcubic commented May 3, 2024

I have an idea for a new feature for jQuery Terminal

In this article are examples of using AbortController to cancel promises (by wrapping them and not resolving when there was an abort signal)

How To Cancel Any Async Task in JavaScript

This could be incorporated with the code for CTRL+D the old code with $.ajax can be removed, and replaced with handler for all promises.

@jcubic jcubic added the feature label May 3, 2024
@jcubic
Copy link
Owner Author

jcubic commented May 3, 2024

The abort signal should be exposed with an API:

terminal::signal()

So the user can use it with fetch:

$('body').terminal(async function(command) {
    const signal = this.signal();
    const res = await fetch('./api?' + command, { signal });
    if (!signal.aborted) {
        const json = await res.json();
        this.echo(json.result);
    }
});

@jcubic
Copy link
Owner Author

jcubic commented May 3, 2024

ref: AbortSignal::timeout()

@jcubic
Copy link
Owner Author

jcubic commented May 6, 2024

term::read() also need a signal.

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

No branches or pull requests

1 participant