• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.version类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@statecraft/core.version的典型用法代码示例。如果您正苦于以下问题:TypeScript version类的具体用法?TypeScript version怎么用?TypeScript version使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了version类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: bitHas

    ;(async () => {
      const qt = store.storeInfo.capabilities.queryTypes
      const q: I.Query = bitHas(qt, I.QueryType.AllKV) ? {type: I.QueryType.AllKV, q:true}
        : bitHas(qt, I.QueryType.StaticRange) ? {type: I.QueryType.StaticRange, q: [{low: sel(''), high: sel('\xff')}]}
        // : qt.has('static range') ? {type: 'static range', q: [{low: sel('mdraw/'), high: sel('mdraw/~')}]}
        : {type: I.QueryType.Single, q:true}
      const rtype = queryTypes[q.type].resultType

      // I would love to just use subResults here, but 
      for await (const {raw, results, versions} of subResults(rtype.type!, store.subscribe(q))) {
        // console.log('results', results)
        
        state.data = rtype.type! === I.ResultType.Range
          ? new Map(results[0])
          : results
        // console.log('val', results, state.data, versions)

        const v = version.vRangeTo(versions)
        if (raw.replace) {
          rtype.mapReplace<any, void>(raw.replace.with, (val, k) => {
            pushOp(k, {v, replace: val})
          })
        }

        raw.txns.forEach(({txn}) => {
          rtype.mapTxn<any, void>(txn, (op, k) => {
            pushOp(k, {v, op})
            return null as any as I.Op<void> // It'd be better to have a forEach .. .eh.
          })
        })

        state.versions = v
        emitter.emit('render')
      }
    })()
开发者ID:josephg,项目名称:statecraft,代码行数:35,代码来源:client.ts


示例3:

 await Promise.all(Array.from(query.q).map(async k => {
   const result = await tn.get(k)
   if (result) {
     const [stamp, value] = result
     if (value != null) results.set(k, opts.noDocs ? 1 : value)
     maxVersion = maxVersion ? versionLib.vMax(maxVersion, stamp) : stamp
   }
 }))
开发者ID:josephg,项目名称:statecraft,代码行数:8,代码来源:fdb.ts


示例4: bakeRange

 results = q.map((range) => {
   const staticRange = (query.type === I.QueryType.Range) ? bakeRange(dbTxn, range) : (range as I.StaticRange)
   const docs = [] // A map might be nicer.
   for (const [k, bytes] of rangeContentIter(dbTxn, staticRange)) {
     const [lastMod, doc] = decode(bytes)
     maxVersion = versionLib.vMax(maxVersion, lastMod)
     docs.push([k, doc])
   }
   return docs
 })
开发者ID:josephg,项目名称:statecraft,代码行数:10,代码来源:lmdb.ts


示例5: rawGet

  const getKVResults = (dbTxn: lmdb.Txn, query: Iterable<I.Key>, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO

    for (let k of query) {
      const [lastMod, doc] = rawGet(dbTxn, k)
      if (doc != null) resultsOut.set(k, opts.noDocs ? 1 : doc)
      // Note we update maxVersion even if the document is null.
      maxVersion = versionLib.vMax(maxVersion, lastMod)
    }

    return maxVersion
  }
开发者ID:josephg,项目名称:statecraft,代码行数:12,代码来源:lmdb.ts


示例6: while

  const getAllResults = (dbTxn: lmdb.Txn, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO
    const cursor = new lmdb.Cursor(dbTxn, dbi)
    let k = cursor.goToRange('\x02') // positioned right after config key
    while (k != null) {
      const bytes = cursor.getCurrentBinaryUnsafe()
      const [lastMod, doc] = decode(bytes)
      if (doc != null) resultsOut.set(k as string, opts.noDocs ? 1 : doc)
      maxVersion = versionLib.vMax(maxVersion, lastMod)

      k = cursor.goToNext()
    }
    cursor.close()

    return maxVersion
  }
开发者ID:josephg,项目名称:statecraft,代码行数:16,代码来源:lmdb.ts


示例7: Error

const lmdbStore = <Val>(inner: I.Store<Val>, location: string): Promise<I.Store<Val>> => {
  const env = new lmdb.Env()

  // console.log('inner', inner)
  if (inner.storeInfo.sources.length !== 1) {
    // It would be trivial though.
    throw new Error('LMDB store with multiple sources not implemented')
  }

  const source: I.Source = inner.storeInfo.sources[0]

  // Check that the directory exists.
  try { fs.mkdirSync(location) }
  catch(e) { if (e.code !== 'EEXIST') throw e }

  env.open({path: location, maxDbs: 2, noTls: true})

  const dbi = env.openDbi({name: null, create: true})
  // const configdb = env.openDbi({name: 'config', create: true})

  // Note: I'm using 'native' Prozess version numbers, so the local store
  // starts at version 0 and event 1 moves us to version 1.
  let version: I.Version = new Uint8Array()

  const setVersion = (txn: lmdb.Txn, v: I.Version) => {
    version = v
    txn.putBinary(dbi, VERSION_KEY, Buffer.from(version))
  }

  // Ok, first do catchup.
  {
    const txn = env.beginTxn()
    const configBytes = txn.getBinary(dbi, CONFIG_KEY)
    if (configBytes == null) {
      // console.log('Database was created - no config!')
      txn.putBinary(dbi, CONFIG_KEY, msgpack.encode({sc_ver: 1, source}))
      setVersion(txn, new Uint8Array(8))
    } else {
      const {sc_ver, source:dbSource} = msgpack.decode(configBytes)
      assert(sc_ver === 1, 'LDMB database was set up using invalid or old statecraft version.')
      assert(dbSource === source, `LDMB database at ${location} is invalid. Delete and restart`)
      version = new Uint8Array(txn.getBinary(dbi, VERSION_KEY))
    }
    txn.commit()
  }
  debug('Opened database at version', version)

  const ready = resolvable()
  // const ready = inner.start!([version])

  // TODO: Generate these based on the opstore.
  const capabilities = {
    queryTypes: bitSet(I.QueryType.AllKV, I.QueryType.KV, I.QueryType.StaticRange, I.QueryType.Range),
    mutationTypes: bitSet(I.ResultType.KV),
  }  

  const decode = (bytes: Buffer | null): [Uint8Array, any] => {
    if (bytes == null) return [V_ZERO, null]
    else {
      const [vBuf, data] = msgpack.decode(bytes)
      return [new Uint8Array(vBuf), data]
    }
  }

  const rawGet = (txn: lmdb.Txn, k: I.Key) => decode(txn.getBinaryUnsafe(dbi, k))

  // TODO: Probably cleaner to write this as iterators? This is simpler / more
  // understandable though.
  const getKVResults = (dbTxn: lmdb.Txn, query: Iterable<I.Key>, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO

    for (let k of query) {
      const [lastMod, doc] = rawGet(dbTxn, k)
      if (doc != null) resultsOut.set(k, opts.noDocs ? 1 : doc)
      // Note we update maxVersion even if the document is null.
      maxVersion = versionLib.vMax(maxVersion, lastMod)
    }

    return maxVersion
  }

  const getAllResults = (dbTxn: lmdb.Txn, opts: I.FetchOpts, resultsOut: Map<I.Key, Val>) => {
    let maxVersion = V_ZERO
    const cursor = new lmdb.Cursor(dbTxn, dbi)
    let k = cursor.goToRange('\x02') // positioned right after config key
    while (k != null) {
      const bytes = cursor.getCurrentBinaryUnsafe()
      const [lastMod, doc] = decode(bytes)
      if (doc != null) resultsOut.set(k as string, opts.noDocs ? 1 : doc)
      maxVersion = versionLib.vMax(maxVersion, lastMod)

      k = cursor.goToNext()
    }
    cursor.close()

    return maxVersion
  }

  const setCursor = (cursor: lmdb.Cursor, sel: I.StaticKeySelector) => {
    let {k, isAfter} = sel
//.........这里部分代码省略.........
开发者ID:josephg,项目名称:statecraft,代码行数:101,代码来源:lmdb.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript net.connectToWS函数代码示例发布时间:2022-05-28
下一篇:
TypeScript core.setSingle函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap