From aa4e3c831631f04e4d81d5bd9b747e364c031078 Mon Sep 17 00:00:00 2001 From: Derek Perez Date: Mon, 3 May 2021 15:43:38 -0700 Subject: [PATCH] use protobufjs.loadSync to ensure schema load timing. (#41) --- riemann/serializer.js | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/riemann/serializer.js b/riemann/serializer.js index 38a94fa..a417bab 100644 --- a/riemann/serializer.js +++ b/riemann/serializer.js @@ -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);