当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript version.vCmp方法代码示例

本文整理汇总了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--
  }
开发者ID:josephg,项目名称:statecraft,代码行数:60,代码来源:fdb.ts

示例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)
        }))
开发者ID:josephg,项目名称:statecraft,代码行数:20,代码来源:fdb.ts

示例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() {
开发者ID:josephg,项目名称:statecraft,代码行数:67,代码来源:lmdb.ts


注:本文中的@statecraft/core.version.vCmp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。