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

214
Vistas
How to use promise on callback from proprietary software

I'm using a software that lets me read a data on it's server using this function :

webMI.data.read(nodeID, function(e){...})
Passes a current property object for every data variable specified by its nodeID to the callback function. You can pass a single nodeID or an array of nodeIDs.

In the callback i get the value i want, but i couldn't get it out and didn't want to make a callback hell After some reading/testing on asyncronous function, i tried using promise but i keep getting the same error and i don't understand why

webMI.data.read("AGENT.OBJECTS.motor.isActive",e => e.value)
.then(result => {
    console.log(result)
})

Uncaught TypeError: webMI.data.read(...) is undefined

I also tried to put it in an async function and using await

async function GetValue(){
    var temp = await webMI.data.read("AGENT.OBJECTS.motor.isActive",function(e){return e.value})
    return temp
}

But temp always return a Promise with state = fullfilled and value = undefined

My goal is to get 1 to X values this way to make a formula

Note that i have no way to modify 'webMI.data.read'

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use the promise constructor and resolve from within the callback

function GetValue(){
    return new Promise(resolve => {
        webMI.data.read("AGENT.OBJECTS.motor.isActive",function(e){resolve(e.value)})
    })
}

Now the GetValue function is async, as it returns a promise and can be awaited.

How to "await" for a callback to return?

about 4 years ago · Juan Pablo Isaza 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