Skip to content

Instantly share code, notes, and snippets.

@konami12
Last active September 29, 2022 17:23
Show Gist options
  • Save konami12/81f7139b54517cb7ff5b2305e342ef7d to your computer and use it in GitHub Desktop.
Save konami12/81f7139b54517cb7ff5b2305e342ef7d to your computer and use it in GitHub Desktop.
fetch-generator-function.js
const fetch = require("node-fetch");
/**
* Se realiza la peticion a la api solicitada
*
* @param {string} url Ruta correspondiente a la API.
* @return {object}
*/
const requestData = async (url) => {
const REQUEST = await fetch(url);
const DATA = await REQUEST.json();
return DATA;
};
/**
* Genera las peticiones a la API
*
* @param {string} url Ruta del API
* @return {Promise}
*/
async function* generateRequest(url) {
const ITEMS = await requestData(url);
let count = 0;
for (let item of ITEMS) {
yield item;
}
}
const API = "https://orca-api-pokemon.herokuapp.com";
const GET_DATA = await generateRequest(`${API}/type/fire`);
let breakRequest = false;
do {
let {value , done} = await GET_DATA.next();
console.log(value);
breakRequest = done;
} while(breakRequest !== true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment