當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。