The official Upgrading to Notebooks 2.0 Guide (§ Generators) details how generator cells are converted in 2.0 using explicit generator functions or IIFEs (async function*).
A practical variation of this pattern occurs when using event streams like Generators.queue() to create reactive filters (e.g., listening to a Vega-Lite brush or brush_x signal on a barChart).
The notebook Generators in Observable 2.0 illustrates a simple workaround using for await:
filter1 = {
const eventStream = Generators.queue((notify) => {
notify("a");
});
// ❌ WORKED IN 1.0; BROKEN IN 2.0:
for (const value of eventStream) {
let filters = await value;
// Perform any optional processing before re-yielding to the notebook
yield filters;
}
}
filter2 = {
const eventStream = Generators.queue((notify) => {
notify("a");
});
// ✅ FIXED IN 2.0 BY SIMPLY ADDING 'await':
for await (const value of eventStream) {
let filters = await value;
// Perform any optional processing before re-yielding to the notebook
yield filters;
}
}