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

Code Call Stack at Initialization and Size Optimization #93

Closed
coatless opened this issue Nov 13, 2023 · 1 comment
Closed

Code Call Stack at Initialization and Size Optimization #93

coatless opened this issue Nov 13, 2023 · 1 comment
Labels
t: feature-request Request the addition of a new feature
Milestone

Comments

@coatless
Copy link
Owner

Right now, we're using multiple views to combat different contexts. Unfortunately, the contexts are not controlled in a way that plays nicely with the main document settings, c.f. #88. Without moving everything into module form and risking running into more publish woes (e.g. webr-*worker.js), we should avoid injecting code in-place in favor of maintaining an internal stack of code and contexts in the HTML document. By moving in this direction, we can gain more utility in introducing a new inline execution mechanic, c.f. #92, and, potentially, allow for document-level resets/re-renders without leaving the page.

The rough sketch of the Lua filter change was prototyped out in: https://github.com/coatless-quarto/catchandrelease

From there, we would need to take advantage of promises and maintain a call stack. A rough idea would be somewhere along the lines of:

// Define an array of asynchronous functions to execute consecutively
const asyncFunctions = [asyncFunction1, asyncFunction2];

function executeAsyncFunctionsConsecutively(functions) {
  // Base case, no code to call
  if (functions.length === 0) {
    console.log("All async functions are done.");
    return;
  }

  // Get and remove the first function from the array
  const currentFunction = functions.shift();

  // Execute the function, once resolved move to the next function
  currentFunction()
    .then(() => executeAsyncFunctionsConsecutively(functions))
    .catch((error) => {
      console.error("Error:", error);
    });
}

executeAsyncFunctionsConsecutively(asyncFunctions);

Though, this might be a bit overkill at the moment.

@coatless
Copy link
Owner Author

Addressed in #118 and #120.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: feature-request Request the addition of a new feature
Projects
None yet
Development

No branches or pull requests

1 participant