Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/inflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ const b4a = require('b4a')
const { Pointer, KeyPointer, ValuePointer, TreeNode } = require('./tree.js')
const { DeltaOp, DeltaCohort, OP_COHORT } = require('./compression.js')

const pending = new WeakMap()

exports.inflate = async function inflate(ptr, config) {
if (ptr.value) return ptr.value
if (pending.has(ptr)) return pending.get(ptr)
const promise = _inflate(ptr, config)
pending.set(ptr, promise)
try {
return await promise
} finally {
pending.delete(ptr)
}
}

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)
Expand Down
Loading