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

323
Views
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
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!