← Commit history

demo: wait for an idle Fusion between library artifacts - a busy main thread reports as add-in not responding

John Lauer ·491440c78e ·2mo ago ·parent 1278a8c
1 file changed +28
web-control-demo.html+28
@@ -1876,6 +1876,31 @@ for (const w of mine) {   // The same standard as the KiCad library card, applied to Fusion: a library IS   // a symbol plus a footprint plus a 3D package, so proving one means opening all   // three and capturing each. John, 2026-08-20: "a library is all 3 of those items".+  // Fusion runs ONE command at a time on its main thread. A slow surface (one was+  // measured at 546s, fusion-bridge#40) keeps the thread busy AFTER the verb has+  // returned, so the next call queues and times out - and the bridge reports that+  // timeout as "add-in not responding", which reads like a dead add-in rather+  // than a busy one. Measured here: the library open succeeded, then the symbol+  // and footprint both failed that way, giving 0/3 on a perfectly healthy Fusion.+  // So wait for drivable between artifacts instead of firing into a busy thread.+  function waitForFusion(c, tries) {+    var n = 0;+    function probe() {+      n++;+      return postVerb("fusion_readiness", {}).then(function (r) {+        var ready = r.s === 200 && r.j && r.j.ready === true;+        if (ready) return true;+        if (r.j && r.j.running === false) { clog(c, "  Fusion is not running - stopping the wait"); return false; }+        if (n >= tries) { clog(c, "  Fusion still busy after ~" + (n * 6) + "s"); return false; }+        return new Promise(function (rs) { setTimeout(rs, 6000); }).then(probe);+      }, function () {+        if (n >= tries) return false;+        return new Promise(function (rs) { setTimeout(rs, 6000); }).then(probe);+      });+    }+    return probe();+  }+   function showFusionLibraryProof(c) {     c.btn.disabled = true;     cardLog(c.card).textContent = "";@@ -1900,6 +1925,8 @@ for (const w of mine) {       ];       return steps.reduce(function (chain, st) {         return chain.then(function () {+          clog(c, "Waiting for Fusion to be idle before the " + st.label + " ...");+          return waitForFusion(c, 100).then(function () {           clog(c, "Proving the " + st.label + " ...");           return postVerb(st.cmd, st.args()).then(function (r) {             var jj = r.j || {};@@ -1922,6 +1949,7 @@ for (const w of mine) {               }             });           });+          });         });       }, Promise.resolve());     }).then(function () {