Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
await escribir en el archivo solo se llama al azar

Estoy usando octokitjs para obtener el sha de un archivo y luego escribir en el archivo. Tengo alrededor de 8 archivos en ese repositorio de Github. Necesito escribir en los archivos uno por uno. Aquí está mi código:

 async function separateCars() { await rss[0].originalItems.forEach(item => { const title = item.title //if else condition to separate car by its type }) } const commitCars = async(car) => { const newCar = transformRssToMD(car.items); async function getSHA(path) { try { const result = await octokit.repos.getContent({ owner: "bob", repo: "car-repo", path: path }); const sha = result?.data?.sha; return sha; } catch (error) { console.log(error); } } function getPath(car) { if(car.title === 'volvo'){ return `volvo.md`; } else if(car.title === 'audi'){ return `audi.md` } else if(car.title === 'benz'){ return `benz.md` } else if(car.title === 'bmw'){ return `bmw.md` } else if(car.title === 'tesla'){ return `tesla.md` } else if(car.title === 'honda'){ return `honda.md` } else if(car.title === 'tata'){ return `tata.md` } else if(car.title === 'suzuki'){ return `suzuki.md` } } async function commitToGH(car){ const path = getPath(car); const sha = await getSHA(path); try { const result = await octokit.repos.createOrUpdateFileContents({ owner: "bob", repo: "car-repo", path: path, message: `latest cars updated`, content: Base64.encode(`${newCars}`), branch: 'main', sha, }); console.log("result", result); return result?.status || 500; } catch (error) { console.log(error); } } const results = await commitToGH(car); } async function callCommits(){ await separateCars().then(()=> { commitCars(vovlo); commitCars(tesla); commitCars(bmw); commitCars(tata); commitCars(suzuki); commitCars(audi); commitCars(honda); commitCars(benz); }); } callCommits(); }

Aquí se llama a getPath 8 veces como se esperaba. Pero getsha solo se llama al azar como 2 veces en ejecución o 4 veces en una ejecución. Y el createorUpdateFileContents también solo se llama al azar. Estoy golpeado con este problema desde hace 2 días. ¿Qué estoy haciendo mal? ¿algún problema con async-await?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda