diff --git a/lib/inflate.js b/lib/inflate.js index 8f5bcce..6c80fb1 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -4,7 +4,18 @@ const { DeltaOp, DeltaCohort, OP_COHORT } = require('./compression.js') exports.inflate = async function inflate(ptr, config) { if (ptr.value) return ptr.value + if (ptr.inflating) return ptr.inflating + ptr.inflating = _inflate(ptr, config) + + try { + return await ptr.inflating + } finally { + ptr.inflating = null + } +} + +async function _inflate(ptr, config) { const [block, context] = await Promise.all([ ptr.context.getBlock(ptr.seq, ptr.core, config), ptr.context.getContext(ptr.core, config) diff --git a/lib/tree.js b/lib/tree.js index e471063..f25b761 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -72,6 +72,8 @@ class TreeNodePointer extends Pointer { this.next = null this.prev = null + + this.inflating = null } commit() {