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