Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from jwasinger/fix-bc-general-state-tests
Browse files Browse the repository at this point in the history
Make sure blockchain init is complete before adding blocks
  • Loading branch information
holgerd77 authored Sep 11, 2017
2 parents 1598106 + 23e4fd3 commit f0070b5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f0070b5

Please sign in to comment.