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

Imported view duplicates echo of async function #987

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

Imported view duplicates echo of async function #987

jcubic opened this issue Dec 3, 2024 · 3 comments
Labels
Bug resolved if issue is resolved, it will be open until merge with master

Comments

@jcubic
Copy link
Owner

jcubic commented Dec 3, 2024

Issue summary

When import a view that contains echo with async function, the async function is duplicated after each import.

Expected behavior

Async function should behave the same as sync ones

Steps to reproduce

  1. Open reproduction demo
  2. import_view make the output show 2 async echo

Browser and OS

Additional notes

The more import_view are added, the more duplicated lines
As many extra async functions as there are import_view calls.

@jcubic jcubic added the Bug label Dec 3, 2024
@jcubic
Copy link
Owner Author

jcubic commented Dec 3, 2024

This is a race condition, this works fine:

term.clear();
term.echo(async () => `<yellow>this is async function</yellow>`);

setTimeout(() => {
    const view = term.export_view();
    term.clear();
    term.import_view(view);
});

Not sure if this is worth fixing, Maybe just document, to not export view after async echo.

@jcubic
Copy link
Owner Author

jcubic commented Dec 3, 2024

This is more problematic, the solution above only works when the async function does nothing. The export view needs to happen after the function is resolved.

@jcubic jcubic removed the won't fix label Dec 3, 2024
jcubic added a commit to jcubic/dialogue that referenced this issue Dec 3, 2024
jcubic added a commit that referenced this issue Dec 9, 2024
@jcubic
Copy link
Owner Author

jcubic commented Dec 9, 2024

To not break the API, the export_view is still synchronous. I've added terminal::view_ready() that allow to wait for all async functions to finish.

jcubic added a commit that referenced this issue Dec 9, 2024
@jcubic jcubic added resolved if issue is resolved, it will be open until merge with master and removed documentation labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

1 participant