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