Search code examples
javascriptprotocol-buffersprotobuf.js

protobuf.js: Is there a synchronous way of loading static code


I've trying to load synchronously protobuf.js static code (generated with pbjs).

According to the documentation, the documented method is asynchronous.

The asynchronous loading is done like that:

protobuf.load("bundle.json", function(err, root) {
    ...
});

As my further code should only be executed after loading is done, I believe synchronous loading would be better.

Is there any way to load it synchronous or is there any tweak to get that done?


Solution

  • Protobuf.js has a synchronous loading method

    You can totally achieve what you want with asynchronous loading. Just put your further code in the callback, or don't add a callback and add your further code to the .then method of the returned Promise.