Skip to content

Commit

Permalink
use protobufjs.loadSync to ensure schema load timing. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
perezd authored May 3, 2021
1 parent 21a2ae4 commit aa4e3c8
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions riemann/serializer.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
var protobuf = require('protobufjs');
var path = require('path');

/* initialize our protobuf schema,
and cache it in memory. */
var riemannSchema;
if (!riemannSchema) {
schemaLoad();
}

function schemaLoad() {
return new Promise((resolve, reject) => {
if (riemannSchema) {
resolve();
}

protobuf.load(path.join(__dirname, '/proto/proto.proto'), (err, root) => {
if (err) {
reject(err);
}

// Pull the message type out.
riemannSchema = root;
resolve();
});
});
}

exports.schemaLoad = schemaLoad;
/* initialize our protobuf schema, and cache it in memory. */
var riemannSchema = protobuf.loadSync(path.join(__dirname, '/proto/proto.proto'));

function _serialize(type, value) {
var messageType = riemannSchema.lookupType(type);
Expand Down

0 comments on commit aa4e3c8

Please sign in to comment.