jquery.terminal icon indicating copy to clipboard operation
jquery.terminal copied to clipboard

Imported view duplicates echo of async function

Open jcubic opened this issue 11 months ago • 3 comments
trafficstars

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 avatar Dec 03 '24 16:12 jcubic

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 avatar Dec 03 '24 18:12 jcubic

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 avatar Dec 03 '24 18:12 jcubic

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 avatar Dec 09 '24 16:12 jcubic