From 23e4fd36c3e0098f50bf56f5e94fa78fb8e15009 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 11 Sep 2017 00:10:27 +0000 Subject: [PATCH] make sure blockchain init is complete before adding blocks --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0c9937a..c2e498e 100644 --- a/index.js +++ b/index.js @@ -139,10 +139,13 @@ Blockchain.prototype.putBlocks = function (blocks, cb) { Blockchain.prototype.putBlock = function (block, cb, isGenesis) { const self = this - // perform put with mutex dance - lockUnlock(function (done) { - self._putBlock(block, done, isGenesis) - }, cb) + // make sure init has completed + self._initLock.await(() => { + // perform put with mutex dance + lockUnlock(function (done) { + self._putBlock(block, done, isGenesis) + }, cb) + }) // lock, call fn, unlock function lockUnlock (fn, cb) {