本文整理汇总了TypeScript中@statecraft/core.version.vCmp方法的典型用法代码示例。如果您正苦于以下问题:TypeScript version.vCmp方法的具体用法?TypeScript version.vCmp怎么用?TypeScript version.vCmp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@statecraft/core.version
的用法示例。
在下文中一共展示了version.vCmp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
const opwatcher = async () => {
try {
// running++
// await new Promise(resolve => setTimeout(resolve, 1000))
if (v0 == null) throw new Error('Inconsistent state - version key missing')
// console.log('initial version', v0)
while (!closed) {
const watch = await rawDb.getAndWatch(VERSION_KEY)
const {value: version, promise} = watch
if (version != null && !v0.equals(version)) {
// TODO: Probably should chunk this?
const ops = await opDb.getRangeAll(
keySelector.firstGreaterThan(v0),
keySelector.firstGreaterThan(version!)
)
// console.log('version', v0, version, ops)
const txns: I.TxnWithMeta<Val>[] = []
for (let i = 0; i < ops.length; i++) {
const [version, v] = ops[i]
const [op, meta] = v
// console.log('v', v0, version)
assert(versionLib.vCmp(v0, version) < 0)
txns.push({
txn: new Map(op),
meta,
versions: [version],
})
}
// console.log('subgroup', v0, '->', version, ops)
subGroup.onOp(0, v0, txns)
v0 = version
}
// If the store was closed between the top of the loop and this point
// (async, remember!) then we explicitly close now. We need to cancel
// the watch immediately because otherwise the node event loop would
// be held open.
if (closed) { watch.cancel(); break }
else cancelWatch = watch.cancel.bind(watch)
// This promise should resolve to false when the watch was cancelled.
// TODO: Check what happens when the database connection is
// interrupted.
await promise
}
} catch (e) {
console.error('Unhandled error in FDB operation watch process', e.message, e.stack)
// Throw to the global exception handler, which will normally crash the process.
process.emit('uncaughtException', e)
}
// running--
}
示例2:
await Promise.all(Array.from(txn.entries()).map(async ([k, op]) => {
const oldValue = await tn.getVersionstampPrefixedValue(k)
// console.log(m, 'oldvalue stamp', oldValue && oldValue.stamp, 'v', v, 'conflict', (oldValue && v) ? vCmp(oldValue.stamp, v) > 0 : 'no compare')
if (v != null && oldValue != null && versionLib.vCmp(oldValue.stamp, v) > 0) {
// console.log('throwing write conflict', m)
throw new err.WriteConflictError('Write conflict in key ' + k)
}
const newVal = fieldOps.apply(oldValue ? oldValue.value : null, op)
// I'm leaving an empty entry in the lmdb database even if newData is
// null so fetch will correctly report last modified versions.
// This can be stripped with a periodically updating baseVersion if
// thats useful.
// if (newVal === undefined) tn.clear(k)
// console.log(m, 'setting', k, newVal)
tn.setVersionstampPrefixedValue(k, newVal)
}))
示例3: Error
//.........这里部分代码省略.........
// console.log('lmdb fetch', results, maxVersion, version)
return Promise.resolve({
bakedQuery,
results,
versions: [{from: maxVersion, to: version}]
})
}
const subGroup = new SubGroup({initialVersion: [version], fetch, getOps: inner.getOps.bind(inner)})
const store: I.Store<Val> = {
storeInfo: {
uid: `lmdb(${inner.storeInfo.uid})`, // TODO: Maybe just re-expose inner.storeinfo.uid? All kv wraps should be identical
sources: [source],
capabilities,
},
async mutate(type, _txn, versions, opts = {}) {
// TODO: Refactor this out by implementing internalDidChange
if (type !== I.ResultType.KV) throw new err.UnsupportedTypeError()
const txn = _txn as I.KVTxn<Val>
// await ready
debug('mutate', txn)
const expectedVersion = (versions && versions[0] != null) ? versions[0]! : version
// Check that the transaction applies cleanly.
const dbTxn = env.beginTxn({readOnly: true})
for (const [k, op] of txn) {
const [v, data] = rawGet(dbTxn, k)
if (expectedVersion.length && versionLib.vCmp(v, expectedVersion) > 0) {
dbTxn.abort()
return Promise.reject(new err.WriteConflictError('Write conflict in key ' + k))
}
try {
if (fieldOps.checkOp) {
fieldOps.checkOp(op, fieldOps.create(data))
}
} catch (e) {
dbTxn.abort()
return Promise.reject(e)
}
}
dbTxn.abort()
// console.log('sendTxn', txn, expectedVersion)
// const resultVersion = await sendTxn(client, txn, opts.meta || {}, version, {})
// We know its valid at the current version, so we're ok to pass that here.
const innerV = versions == null ? [version] : versions.slice()
innerV[0] = version
const result = await inner.mutate(I.ResultType.KV, txn, innerV, opts)
debug('mutate cb', result)
return result
},
fetch,
getOps: inner.getOps.bind(inner),
subscribe: subGroup.create.bind(subGroup),
close() {