Skip to content

Waiting js till pyscript loads up #1587

Answered by WebReflection
MasterANK asked this question in Q&A
Discussion options

You must be logged in to vote

OK, this is tested and working as expected. It simply tries until the interpreter is ready, starting to try when the py-script element is defined and never before.

This is not super elegant but it gets the job done in a non-blocking, prettty fast, way.

(IMHO) We should have a better way to do this and we will have such better way in next.

<script type="module">
  const interpreter = await customElements.whenDefined('py-script').then(
    function retry() {
      return pyscript.interpreter ||
             new Promise(resolve => queueMicrotask(resolve)).then(retry);
    }
  );

  console.log('Ready', interpreter.globals);
</script>

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@MasterANK
Comment options

@WebReflection
Comment options

@WebReflection
Comment options

Answer selected by MasterANK
@MasterANK
Comment options

@WebReflection
Comment options

@MasterANK
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants