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


TypeScript Writable.on方法代码示例

本文整理汇总了TypeScript中stream.Writable.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Writable.on方法的具体用法?TypeScript Writable.on怎么用?TypeScript Writable.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stream.Writable的用法示例。


在下文中一共展示了Writable.on方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Writable

      fromClusterIds.forEach(fromClusterId => {
        let addressMerger = new Writable({
          objectMode: true,
          write: async (data: {key: {clusterId: number, balance: number, address: string}, value: {}}, encoding, callback) => {
            newAddressesCount++;
            let address = new ClusterAddress(data.key.balance, data.key.address);
            await this.db.writeBatchService.push(
              this.clusterAddressTable.putOperation({clusterId: toClusterId, balance: address.balance, address: address.address}, {})
            );
            await this.db.writeBatchService.push(
              this.clusterAddressTable.delOperation({clusterId: fromClusterId, balance: address.balance, address: address.address})
            );
            await this.db.writeBatchService.push(
              this.addressClusterTable.putOperation({address: address.address}, {clusterId: toClusterId})
            );
            callback(null);
          }
        });
        let nextClusterId = new ClusterId(fromClusterId.height, fromClusterId.txN, fromClusterId.outputN+1);
        this.clusterAddressTable.createReadStream({
          gte: {clusterId: fromClusterId},
          lt: {clusterId: nextClusterId}
        }).pipe(addressMerger);

        addressMerger.on('finish', async () => {
          await this.db.writeBatchService.push(
            this.clusterAddressCountTable.delOperation({clusterId: fromClusterId})
          );
          clustersToMerge--;
          if (clustersToMerge === 0) resolve();
        });
      });
开发者ID:Antti-Kaikkonen,项目名称:CoinClustering,代码行数:32,代码来源:cluster-address-service.ts

示例2: test

test('tapToVSError', t => {
  const s = new stream.Readable();
  s.push(testString2);
  s.push(null);

  const w = new stream.Writable();
  let resultString = '';
  w._write = function (chunk, encoding, done) {
    //console.log('+=+' + chunk.toString());
    resultString += chunk.toString();
    done();
  };

  const option = new Options(null, 'c:/base');
  const tapToVSError = new TapToVSError(option);

  const teststream = tapToVSError.stream();
  s.pipe(teststream).pipe(w);

  w.on('finish', function () {
    console.log('resultString = ' + resultString);
    t.ok(teststream, 'teststream');
    t.ok(resultString, 'resultString');
    t.end();
  });
});
开发者ID:Quobject,项目名称:tap-to-html,代码行数:26,代码来源:index.spec.ts

示例3: Writable

      fromClusters.forEach(fromCluster => {
        let clusterBalancePromise = this.getClusterBalanceDefaultZero(fromCluster);
        let clusterTransactionCount = 0;

        let txMerger = new Writable({
          objectMode: true,
          write: async (data: {key: {height: number, n: number}, value: {txid: string, balanceChange: number}}, encoding, callback) => {
            clusterTransactionCount++;
            let tx: ClusterTransaction = new ClusterTransaction(
              data.value.txid,
              data.key.height,
              data.key.n,
              data.value.balanceChange
            );
            if (!txIdToOldTransationPromise.has(tx.txid)) {
              txIdToOldTransationPromise.set(tx.txid, this.getClusterTransactionDefaultUndefined(toCluster, tx.height, tx.n));
            }
            let txToMerge = txidToTransactionToMerge.get(tx.txid)
            if (txToMerge) {
              txToMerge.balanceChange += tx.balanceChange;
            } else {
              txidToTransactionToMerge.set(tx.txid, tx);
            }
            await this.db.writeBatchService.push(
              this.clusterTransactionTable.delOperation({clusterId: fromCluster, height: tx.height, n: tx.n})
            );
            callback(null);
          }
        });

        let nextClusterId = new ClusterId(fromCluster.height, fromCluster.txN, fromCluster.outputN+1);
        this.clusterTransactionTable.createReadStream({
          gte: {clusterId: fromCluster},
          lt: {clusterId: nextClusterId}
        }).pipe(txMerger);

        txMerger.on('finish', async () => {
          await this.db.writeBatchService.push(
            this.clusterBalanceTable.delOperation({clusterId: fromCluster})
          );
          await this.db.writeBatchService.push(
            this.clusterTransactionCountTable.delOperation({clusterId: fromCluster})
          );
          let clusterBalance = await clusterBalancePromise;
          fromClusterBalanceSum += clusterBalance;
          if (clusterTransactionCount > 0) {
            await this.db.writeBatchService.push(
              this.balanceToClusterTable.delOperation({balance: clusterBalance, clusterId: fromCluster})
            );
          }
          clustersToMerge--;
          if (clustersToMerge === 0) resolve();
        });

      });
开发者ID:Antti-Kaikkonen,项目名称:CoinClustering,代码行数:55,代码来源:cluster-transaction-service.ts

示例4: doProcessing

async function doProcessing() {
  await db.writeBatchService.process();
  let height = await rpcApi.getRpcHeight();
  console.log("rpc height", height);
  let lastMergedHeight: number = await blockImportService.getLastMergedHeight();
  let lastSavedTxHeight: number = await blockImportService.getLastSavedTxHeight();
  console.log("last saved tx height", lastSavedTxHeight);
  let blockWriter: Writable;
  let startHeight: number;
  let toHeight: number;
  if (lastMergedHeight < height-stay_behind_blocks) {
    startHeight = lastMergedHeight > -1 ? lastMergedHeight + 1 : 1;
    toHeight = height-stay_behind_blocks;
    console.log("merging between blocks", startHeight, "and", toHeight);
    blockWriter = new Writable({
      objectMode: true,
      write: async (block: BlockWithTransactions, encoding, callback) => {
        await blockImportService.blockMerging(block);
        callback(null);
      }
    });
  } else if (lastSavedTxHeight < height-stay_behind_blocks) {
    startHeight = lastSavedTxHeight > -1 ? lastSavedTxHeight + 1 : 1;
    toHeight = lastMergedHeight;
    console.log("saving transactions between blocks", startHeight, "and", toHeight);
    blockWriter = new Writable({
      objectMode: true,
      write: async (block: BlockWithTransactions, encoding, callback) => {
        await blockImportService.saveBlockTransactionsAsync(block);
        blockTimeService.setTime(block.height, block.time);
        callback(null);
      }
    });
  } else {
    setTimeout(doProcessing, 10000);
    return;
  }

  let blockReader = blockchainReader.createReadStream(startHeight, toHeight);
  blockReader.pipe(blockWriter);

  let interval = setInterval(()=>{
    console.log("blockWriter", blockWriter.writableLength);
  }, 5000);
  
  blockWriter.on('finish', () => {
    clearInterval(interval);
    setTimeout(doProcessing, 0);
  });
}
开发者ID:Antti-Kaikkonen,项目名称:CoinClustering,代码行数:50,代码来源:app.ts

示例5: Promise

 await new Promise((resolve, reject) => {
   writable.on('finish', () => {
     resolve();
   });  
   missingHeightTimeReader.pipe(writable);
 });
开发者ID:Antti-Kaikkonen,项目名称:CoinClustering,代码行数:6,代码来源:block-time-service.ts

示例6: resolve

 return new Promise<string>((resolve, reject) => {
   stream.on('data', chunk => chunks.push(chunk))
   stream.on('error', reject)
   stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
 });
开发者ID:Microsoft,项目名称:vsts-tasks,代码行数:5,代码来源:util.ts


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