Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Javascript Async/Await dentro de la promesa

Tengo métodos en una clase como se muestra a continuación. La espera en la devolución de llamada no funciona. Si hay un elemento duplicado, available_quantity dentro de Api.get debe actualizarse para el siguiente elemento, pero se muestra la misma cantidad. Creo que he usado Async/Await correctamente pero aún así no funciona. Por favor, ayúdame a resolverlo.

 async checkItems(callback){ for(const items of (this.all_items)) { let newItem = items.product_id.id; //item id let added_quantity =items.quantity; //total quantity to buy await Api.get('materials/get/'+newItem).then(async (data) => { //gets item data from inventory let available_quantity = data.quantity; //get total quantity available in inventory if (added_quantity <= available_quantity){ //if total quantity available in inventory is greater than buying quantity await callback([newItem,(available_quantity - added_quantity)]); //all i want to do is wait for this callback to complete before moving to next item in for loop. } else{ items.quantity = 0; //if total quantity available in inventory is less than buying quantity set the buying quantity to 0 } }); } }, updateInventory(itemData){ return Api.post('/materials/update', { id: itemData[0], quantity: itemData[1], }).catch(() => {}); }, await this.checkItems(this.updateInventory);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!