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


TypeScript Observable.subscribe方法代码示例

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


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

示例1: to

  to(exchange: string, iO: Observable<any>): Subscription<any> {
    let channel, conn, cachedItems = [];
    let queue = uuid.v4();

    connect(this.config.connString)
    .then(c => conn = c && c.createChannel())
    .then(c => {
      channel = c;

      channel.assertExchange(exchange, 'fanout');
      cachedItems.forEach(item => {
        channel.publish(exchange, '', new Buffer(item));
      });
    })
    .catch(err => { throw err; });

    return iO
      .subscribe(
        msg => {
          if (!channel) {
            return cachedItems.push(msg);
          }

          channel.publish(exchange, '', new Buffer(msg));
        },
        err => console.error(`rabbitSink err, queue: ${queue}`, err),
        () => {
          if (conn) {
            channel.publish(exchange, '', new Buffer('__done'));
            conn.close()
          }
        }
      );
  }
开发者ID:jonesnc,项目名称:gustav,代码行数:34,代码来源:GustavRabbit.ts

示例2: httpDriver

export function httpDriver(input$: Observable<any>, options?: RequestInit): Subject<any> {
    const result = new Subject();
    input$.subscribe((url: string) => {
        fetch(url, options).then(i => {
           result.next(i);
        });        
    });
    return result;
};
开发者ID:pvasek,项目名称:mobx-app-model,代码行数:9,代码来源:httpDriver.ts

示例3: to

  to(channelName: string, iO: Observable<any>): Subscription<any> {
    this.initChannel(channelName);

    return iO.subscribe(
      item => this.channels[channelName].forEach(fn => fn(item)),
      err => { throw err; },
      () => this.channels[channelName].forEach(fn => fn('__done'))
    );
  }
开发者ID:jonesnc,项目名称:gustav,代码行数:9,代码来源:GustavMem.ts

示例4: to

 to(channelName: string, iO: Observable<any>): Subscription<any> {
   let client = this.getClient();
   return iO.subscribe(
     item => {
       if (typeof item !== 'string') {
         item = JSON.stringify(item);
       }
       client.publish(channelName, item);
     },
     err => { throw err; },
     () => client.publish(channelName, '__done')
   );
 }
开发者ID:jonesnc,项目名称:gustav,代码行数:13,代码来源:GustavRedis.ts


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