Skip to content

Ensure custom types run queued like it is for non custom types #64

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

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/core.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions esm/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export const handleCustomType = (node) => {
for (const selector of CUSTOM_SELECTORS) {
if (node.matches(selector)) {
const type = types.get(selector);
const details = registry.get(type);
const { resolve } = waitList.get(type);
const { options, known } = registry.get(type);
const { options, known } = details;
if (!known.has(node)) {
known.add(node);
const {
Expand Down Expand Up @@ -143,11 +144,11 @@ export const handleCustomType = (node) => {
runEvent: module.runEvent.bind(module, interpreter),
};

resolve(resolved);

if (error) onerror?.(error, node);

onInterpreterReady?.(resolved, node);
details.queue = details.queue.then(() => {
resolve(resolved);
if (error) onerror?.(error, node);
return onInterpreterReady?.(resolved, node);
});
});
}
}
Expand Down Expand Up @@ -225,6 +226,7 @@ export const define = (type, options) => {
registry.set(type, {
options: assign({ env: type }, options),
known: new WeakSet(),
queue: Promise.resolve(),
});

if (!dontBother) addAllListeners(document);
Expand Down
28 changes: 28 additions & 0 deletions test/queue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Polyscript queue</title>
<script type="module">
import { define } from "../../core.js";
define("mpy", {
interpreter: "micropython",
async onInterpreterReady({ run }, element) {
let code = element.textContent;
if (element.src)
code = await fetch(element.src).then(b => b.text());
run(code);
}
});
</script>
</head>
<body>
<script type="mpy" src="one.py"></script>
<script type="mpy">print('inline one')</script>
<script type="mpy" src="two.py"></script>
<script type="mpy">print('inline two')</script>
<script type="mpy" src="three.py"></script>
<script type="mpy">print('inline three')</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/queue/one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('src one')
1 change: 1 addition & 0 deletions test/queue/three.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('src three')
1 change: 1 addition & 0 deletions test/queue/two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('src two')