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

212
Vistas
Llamar a la función asíncrona en un ciclo while

Tengo que leer un valor de un dispositivo BLE y luego escribirle otro valor, así que esta es mi función para hacerlo:

 getBit = (device) => { try { device.readCharacteristicForService(this.state.sUuid, this.state.cUuid2) .then((read) => { switch (this.toHexByte(read.value)) { case 'ee': this.setState({ countC0: 0 }); break; case 'c0': this.setState({ countC0: this.state.countC0 + 1 }); break; default: // the bit I want to stock this.setState({ resId: [...this.state.resId, this.toHexByte(read.value)], countC0: 0 }); break; } device.writeCharacteristicWithoutResponseForService(this.state.sUuid, this.state.cUuid2, this.state.respBit) }) return } catch (err) { console.log("find catch error:", err); } }

pero tengo que llamar a esta función hasta que obtenga el mismo bit ( 'c0' ) 3 veces, así que hago un bucle así:

 while (countC0 < 15) { this.getBit(device); countC0++; }

El problema es que recibo Please report: Excessive number of pending callbacks: 501 porque estoy llamando a una función asíncrona en un bucle while.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

esto debería hacerlo

 getBit = async (device) => { try { const read = await device.readCharacteristicForService(this.state.sUuid, this.state.cUuid2) switch (this.toHexByte(read.value)) { case 'ee': this.setState({ countC0: 0 }); break; case 'c0': this.setState({ countC0: this.state.countC0 + 1 }); break; default: // the bit I want to stock this.setState({ resId: [...this.state.resId, this.toHexByte(read.value)], countC0: 0 }); } device.writeCharacteristicWithoutResponseForService(this.state.sUuid, this.state.cUuid2, this.state.respBit) } catch (err) { console.log("find catch error:", err); } }
 while (countC0 < 15) { await this.getBit(device); countC0++; }
about 4 years ago · Santiago Trujillo Denunciar
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