const fetch = require("node-fetch");
let generator = null;
function* gen() {
try {
const todo1 = yield getTodos(`https://jsonplaceholder.typicode.com/todos`);
console.log(todo1);
const todo2 = yield getTodos(
`https://jsonplaceholder.typicode.com/todos/66`
);
setTimeout(() => {
console.log(todo2);
}, 5000);
} catch (error) {
console.log(error);
}
}
function getTodos(url) {
fetch(url)
.then(response => response.json())
.then(json => {
generator.next(json);
})
.catch(error => {
generator.next(error);
});
}
generator = gen();
generator.next();
-
Notifications
You must be signed in to change notification settings - Fork 0
MonguDykrai/generator-function-demo
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published