Skip to content

Instantly share code, notes, and snippets.

@azu
Created March 2, 2024 06:39
Show Gist options
  • Save azu/8eaf5f74c9409a94f8ff98d090d33c9a to your computer and use it in GitHub Desktop.
Save azu/8eaf5f74c9409a94f8ff98d090d33c9a to your computer and use it in GitHub Desktop.
const draw = (output) => console.log(output);
const getWeather = async (city) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return "sunny";
};
const render = async function* ({ city }) {
yield `<Spinner />`;
const weather = await getWeather(city);
return `<Weather info=${weather} />`;
};
// Please draw the weather after using this `render`.
async function main() {
const gen = render({ city: "New York" });
while (true) {
const { value, done } = await gen.next();
draw(value);
if (done) {
break;
}
}
}
await main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment