jquery.terminal
jquery.terminal copied to clipboard
Imported view duplicates echo of async function
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
- Open reproduction demo
import_viewmake 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.
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.
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.
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.