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


TypeScript event-stream.mapSync函数代码示例

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


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

示例1: Promise

 new Promise(res => {
   this.server.pipe(es.mapSync((e:any) => {
     if (e.blockResolutionError === expectedError) {
       res()
     }
   }))
 }),
开发者ID:duniter,项目名称:duniter,代码行数:7,代码来源:toolbox.ts

示例2: typeDocument

export function typeDocument() {
  return es.mapSync((obj: any) => {
    if (obj.joiners !== undefined) {
      obj.documentType = 'block'
    }
    else if (obj.bcEvent !== undefined) {
      return
    }
    else if (obj.wotb_id !== undefined) {
      obj.documentType = 'identity'
    }
    else if (obj.idty_issuer !== undefined) {
      obj.documentType = 'certification'
    }
    else if (obj.type === 'IN') {
      obj.documentType = 'membership'
    }
    else if (obj.unlocks !== undefined) {
      obj.documentType = 'transaction'
    }
    else {
      console.log('Unknown')
      console.log(obj)
    }
    return obj
  })
}
开发者ID:duniter,项目名称:remuniter,代码行数:27,代码来源:test-typedoc.ts

示例3: loadConf

  async loadConf(useDefaultConf:any = false) {
    logger.debug('Loading conf...');
    this.conf = await this.dal.loadConf(this.overrideConf, useDefaultConf)
    // Default values
    this.conf.remoteipv6       = this.conf.remoteipv6 === undefined ?        this.conf.ipv6                               : this.conf.remoteipv6
    this.conf.remoteport       = this.conf.remoteport === undefined ?        this.conf.port                               : this.conf.remoteport
    this.conf.c                = this.conf.c === undefined ?                 constants.CONTRACT.DEFAULT.C                 : this.conf.c
    this.conf.dt               = this.conf.dt === undefined ?                constants.CONTRACT.DEFAULT.DT                : this.conf.dt
    this.conf.ud0              = this.conf.ud0 === undefined ?               constants.CONTRACT.DEFAULT.UD0               : this.conf.ud0
    this.conf.stepMax          = this.conf.stepMax === undefined ?           constants.CONTRACT.DEFAULT.STEPMAX           : this.conf.stepMax
    this.conf.sigPeriod        = this.conf.sigPeriod === undefined ?         constants.CONTRACT.DEFAULT.SIGPERIOD         : this.conf.sigPeriod
    this.conf.msPeriod         = this.conf.msPeriod === undefined ?          constants.CONTRACT.DEFAULT.MSPERIOD          : this.conf.msPeriod
    this.conf.sigStock         = this.conf.sigStock === undefined ?          constants.CONTRACT.DEFAULT.SIGSTOCK          : this.conf.sigStock
    this.conf.sigWindow        = this.conf.sigWindow === undefined ?         constants.CONTRACT.DEFAULT.SIGWINDOW         : this.conf.sigWindow
    this.conf.sigValidity      = this.conf.sigValidity === undefined ?       constants.CONTRACT.DEFAULT.SIGVALIDITY       : this.conf.sigValidity
    this.conf.msValidity       = this.conf.msValidity === undefined ?        constants.CONTRACT.DEFAULT.MSVALIDITY        : this.conf.msValidity
    this.conf.sigQty           = this.conf.sigQty === undefined ?            constants.CONTRACT.DEFAULT.SIGQTY            : this.conf.sigQty
    this.conf.idtyWindow       = this.conf.idtyWindow === undefined ?        constants.CONTRACT.DEFAULT.IDTYWINDOW        : this.conf.idtyWindow
    this.conf.msWindow         = this.conf.msWindow === undefined ?          constants.CONTRACT.DEFAULT.MSWINDOW          : this.conf.msWindow
    this.conf.xpercent         = this.conf.xpercent === undefined ?          constants.CONTRACT.DEFAULT.X_PERCENT         : this.conf.xpercent
    this.conf.percentRot       = this.conf.percentRot === undefined ?        constants.CONTRACT.DEFAULT.PERCENTROT        : this.conf.percentRot
    this.conf.powDelay         = this.conf.powDelay === undefined ?          constants.CONTRACT.DEFAULT.POWDELAY          : this.conf.powDelay
    this.conf.avgGenTime       = this.conf.avgGenTime === undefined ?        constants.CONTRACT.DEFAULT.AVGGENTIME        : this.conf.avgGenTime
    this.conf.dtDiffEval       = this.conf.dtDiffEval === undefined ?        constants.CONTRACT.DEFAULT.DTDIFFEVAL        : this.conf.dtDiffEval
    this.conf.medianTimeBlocks = this.conf.medianTimeBlocks === undefined ?  constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS  : this.conf.medianTimeBlocks
    this.conf.rootoffset       = this.conf.rootoffset === undefined ?        0                                            : this.conf.rootoffset
    this.conf.forksize         = this.conf.forksize === undefined ?          constants.BRANCHES.DEFAULT_WINDOW_SIZE       : this.conf.forksize
    // 1.3.X: the msPeriod = msWindow
    this.conf.msPeriod         = this.conf.msPeriod === undefined ?          this.conf.msWindow                           : this.conf.msPeriod
    // Default keypair
    if (!this.conf.pair || !this.conf.pair.pub || !this.conf.pair.sec) {
      // Create a random key
      this.conf.pair = randomKey().json()
    }
    // Extract key pair
    this.keyPair = KeyGen(this.conf.pair.pub, this.conf.pair.sec);
    this.sign = (msg:string) => this.keyPair.sign(msg)
    // Blockchain object
    this.blockchain = new DuniterBlockchain(new SQLBlockchain(this.dal), this.dal);
    // Update services
    this.IdentityService.setConfDAL(this.conf, this.dal)
    this.MembershipService.setConfDAL(this.conf, this.dal)
    this.PeeringService.setConfDAL(this.conf, this.dal, this.keyPair)
    this.BlockchainService.setConfDAL(this.conf, this.dal, this.keyPair)
    this.TransactionsService.setConfDAL(this.conf, this.dal)

    // Messages piping
    this.BlockchainService
      .pipe(es.mapSync((e:any) => {
        if (e.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || e.bcEvent === OtherConstants.BC_EVENT.SWITCHED) {
          this.emitDocument(e.block, DuniterDocument.ENTITY_BLOCK)
          this.emit('bcEvent', e)
        }
        this.streamPush(e)
      }))

    return this.conf;
  }
开发者ID:Kalmac,项目名称:duniter,代码行数:58,代码来源:server.ts

示例4: Promise

    await new Promise(res => {
      source
        .pipe(protection)
        .pipe(es.mapSync(() => {
        nbDocs++
        if (nbDocs >= 2) {
          res()
        }
      }))

      // Writing
      source.push({ joiners: [] }) // A block
      source.push({ joiners: [] }) // A block
      source.push({ endpoints: [] }) // A peer
    })
开发者ID:duniter,项目名称:duniter,代码行数:15,代码来源:single_write.ts

示例5: parse_file_line

export function parse_file_line(file_path : string, parse : (line:string)=>void, error : () => void, success  : () => void){
        let fs = require('fs')
        let es = require('event-stream');
                
        let stream = fs.createReadStream(file_path).pipe(es.split()).pipe(
            es.mapSync(function(line){
                stream.pause();
                
                parse(line);               
                
                stream.resume();    
            }).on('error',function(){
                error();
            }).on('end',function(){
                success();
            })
        );    
}
开发者ID:hcyang1012,项目名称:vscode_ctags,代码行数:18,代码来源:file_manager.ts

示例6: progressBars

export function progressBars(buildStream, output) {
    var multi = multiline(output)

    buildStream.pipe(JSONStream.parse(null))
        .pipe(es.mapSync(function (data) {
            if(data.status) {
                var line = data.status
                if (data.progress) {
                    line += ' ' + data.progress
                }
                multi.update(data.id, line);
            } else if(data.stream) {
                output.write(data.stream.toString());
            }
            return data
        }))

    // buildStream.pipe(process.stdout);
}
开发者ID:zojeda,项目名称:docker-workspace,代码行数:19,代码来源:utils.ts

示例7: WebSocketServer

  }, (httpServer:any) => {

    let currentBlock = {};
    let wssBlock = new WebSocketServer({
      server: httpServer,
      path: '/ws/block'
    });
    let wssPeer = new WebSocketServer({
      server: httpServer,
      path: '/ws/peer'
    });
    let wssHeads = new WebSocketServer({
      server: httpServer,
      path: '/ws/heads'
    });

    wssBlock.on('error', function (error:any) {
      logger && logger.error('Error on WS Server');
      logger && logger.error(error);
    });

    wssBlock.on('connection', function connection(ws:any) {
      co(function *() {
        try {
          currentBlock = yield server.dal.getCurrentBlockOrNull();
          if (currentBlock) {
            const blockDTO:BlockDTO = BlockDTO.fromJSONObject(currentBlock)
            ws.send(JSON.stringify(block2HttpBlock(blockDTO)))
          }
        } catch (e) {
          logger.error(e);
        }
      });
    });

    wssHeads.on('connection', async (ws:any) => {
      if (server.ws2pCluster) {
        try {
          ws.send(JSON.stringify(await server.ws2pCluster.getKnownHeads()))
        } catch (e) {
          logger.error(e);
        }
      }
    })
    wssHeads.broadcast = (data:any) => wssHeads.clients.forEach((client:any) => client.send(data));

    wssBlock.broadcast = (data:any) => wssBlock.clients.forEach((client:any) => {
      try {
        client.send(data);
      } catch (e) {
        logger && logger.error('error on ws: %s', e);
      }
    });
    wssPeer.broadcast = (data:any) => wssPeer.clients.forEach((client:any) => client.send(data));

    // Forward current HEAD change
    server
      .on('bcEvent', (e) => {
        if (e.bcEvent === OtherConstants.BC_EVENT.HEAD_CHANGED || e.bcEvent === OtherConstants.BC_EVENT.SWITCHED) {
          try {
            // Broadcast block
            currentBlock = e.block;
            const blockDTO:BlockDTO = BlockDTO.fromJSONObject(currentBlock)
            wssBlock.broadcast(JSON.stringify(block2HttpBlock(blockDTO)))
          } catch (e) {
            logger && logger.error('error on ws mapSync:', e);
          }
        }
      })
    // Forward peers documents
    server
      .pipe(es.mapSync(function(data:any) {
        try {
          // Broadcast peer
          if (data.endpoints) {
            const peerDTO = PeerDTO.fromJSONObject(data)
            const peerResult:HttpPeer = {
              version: peerDTO.version,
              currency: peerDTO.currency,
              pubkey: peerDTO.pubkey,
              block: peerDTO.blockstamp,
              endpoints: peerDTO.endpoints,
              signature: peerDTO.signature,
              raw: peerDTO.getRaw()
            }
            wssPeer.broadcast(JSON.stringify(peerResult));
          }
          // Broadcast heads
          else if (data.ws2p === 'heads' && data.added.length) {
            wssHeads.broadcast(JSON.stringify(data.added));
          }
        } catch (e) {
          logger && logger.error('error on ws mapSync:', e);
        }
      }));
  });
开发者ID:duniter,项目名称:duniter,代码行数:96,代码来源:bma.ts


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