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

324
Vistas
protobufjs load() to execute synchronously in browser

I have proto file that contains all the message definitions. I am currently working on a reactjs project in which I want to dynamically use some of these proto models inside js code, and for this I am using the protobufjs library.

I have a function within which I invoke protobuf.load() to create a new object of type defined in the proto file. The code for the function looks something like this:

function doSomething () {
  // This is what I want to return
  let result = [];

  // Load the proto models and extract necessary info
  protobuf.load(protoFile, function(err, root) {
      if (err)
          throw err;
      const someMessageType = root.lookupType("someMessageType");

      // res is actually populated here
      res = Object.keys(someMessageType.fields);
  });

  return res;
}

On calling doSomething(), the result is always an empty array returned as the load function is executed asynchronously (as I understand).

Is there a clean way to make the load execute to completion before the result is returned? It is okay if the UI freezes and it is not a concern.

The protobufjs documentation specifies another syntax

protobuf.load("awesome.proto")
.then(function(root) {
   ...
});

On trying this, I get: Error: illegal token '<' (models.proto, line 1)

I am a novice when it comes to working with js. Any help on this issue would be of great help. Thanks in advance!

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