observablehq / runtime

The reactive dataflow runtime that powers Observable Framework and Observable notebooks
https://observablehq.com/@observablehq/how-observable-runs
ISC License
1.01k stars 71 forks source link

use setTimeout instead of setImmediate (for better compatibility with Deno) #331

Closed keystroke closed 2 years ago

keystroke commented 2 years ago

When running in Deno, I need to execute notebooks like this:

window.setImmediate = func => setTimeout(func, 0);
const { Runtime } = await import(
  "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js"
);

This requires me to set a mock / pollyfill of the setImmediate function, and then use a dynamic import for the runtime module. setTimeout should serve the same purpose and work in a wider variety of environments.

keystroke commented 2 years ago

I added this so I could run the notebooks in Deno

mbostock commented 2 years ago

I’d prefer to use setImmediate if available, but if neither requestAnimationFrame nor setImmediate are available, we can fallback again to setTimeout.

mbostock commented 2 years ago

Fixed in c439e62bb8922fbab6ba2ecc4b4f245d72fc7bfa. Thanks for the suggestion.

keystroke commented 2 years ago

@mbostock Thanks for the quick reply and addition! I am using this with a Netlify edge service I built (https://obs.run) to provide auto-generated wrapper scripts for executing ObservableHQ notebooks in Deno: https://observablehq.com/@keystroke/obs-run