當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Subscription.add方法代碼示例

本文整理匯總了TypeScript中rxjs/Rx.Subscription.add方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subscription.add方法的具體用法?TypeScript Subscription.add怎麽用?TypeScript Subscription.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/Rx.Subscription的用法示例。


在下文中一共展示了Subscription.add方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Subscription

    return Observable.create(o => {
      const disposables = new Subscription()
      log.debug(
        `Subscribing to topic [${topic}]. Is connected [${this.isConnected}]`
      )

      if (!this.isConnected) {
        o.error(
          new Error(
            `Session not connected, can\'t subscribe to topic [${topic}]`
          )
        )
        return disposables
      }

      let subscription
      this.autobahn.session
        .subscribe(topic, (response: Array<any>) => {
          this.logResponse(topic, response)
          o.next(response[0])
        })
        .then(
          sub => {
            // subscription succeeded, subscription is an instance of autobahn.Subscription
            log.verbose(`subscription acked on topic [${topic}]`)
            subscription = sub
          },
          (error: Error) => {
            // subscription failed, error is an instance of autobahn.Error
            log.error(`Error on topic ${topic}`, error)
            o.error(error)
          }
        )

      disposables.add(
        new Subscription(() => {
          if (!subscription) {
            return
          }
          try {
            this.autobahn.session
              .unsubscribe(subscription)
              .then(
                gone =>
                  log.verbose(`Successfully unsubscribing from topic ${topic}`),
                err => log.error(`Error unsubscribing from topic ${topic}`, err)
              )
          } catch (err) {
            log.error(`Error thrown unsubscribing from topic ${topic}`, err)
          }
        })
      )
      return disposables
    })
開發者ID:carlosrfernandez,項目名稱:ReactiveTraderCloud,代碼行數:54,代碼來源:connection.ts

示例2: createExecuteTradeResponse

 .subscribe(limitCheckResult => {
   if (limitCheckResult) {
     const request = serviceClient
       .createRequestResponseOperation(
         'executeTrade',
         executeTradeRequest
       )
       .publish()
       .refCount()
     disposables.add(
       Observable.merge(
         request
           .map(dto => {
             const trade = tradeMapper.mapFromTradeDto(dto.Trade)
             log.info(
               `execute response received for: ${executeTradeRequest}. Status: ${trade.status}`,
               dto
             )
             return createExecuteTradeResponse(trade)
           })
           // if we never receive a response, mark request as complete
           .timeout(
             EXECUTION_REQUEST_TIMEOUT_MS,
             Scheduler.asap.schedule(() =>
               createExecuteTradeResponseForError(
                 'Trade execution timeout exceeded',
                 executeTradeRequest
               )
             )
           ),
         // show timeout error if request is taking longer than expected
         Observable.timer(EXECUTION_CLIENT_TIMEOUT_MS)
           .map(() =>
             createExecuteTradeResponseForError(
               'Trade execution timeout exceeded',
               executeTradeRequest
             )
           )
           .takeUntil(request)
       ).subscribe(o)
     )
   } else {
     o.next(
       createExecuteTradeResponseForError(
         'Credit limit exceeded',
         executeTradeRequest
       )
     )
   }
 })
開發者ID:carlosrfernandez,項目名稱:ReactiveTraderCloud,代碼行數:50,代碼來源:executionService.ts

示例3: constructor

 constructor(userName: string, autobahn: AutobahnConnectionProxy) {
   this.disposables = new Subscription()
   Guard.isDefined(autobahn, 'autobahn required')
   Guard.isString(userName, 'userName required')
   this.userName = userName
   this.autobahn = autobahn
   this.connectionStatusSubject = new BehaviorSubject(ConnectionStatus.idle)
   this.connectionTypeMapper = new ConnectionTypeMapper()
   this.connectCalled = false
   this.isConnected = false
   this.autoDisconnectDisposable = new SerialSubscription()
   this.connectionUrl = ''
   this.connectionType = ConnectionType.Unknown
   this.disposables.add(this.autoDisconnectDisposable)
 }
開發者ID:carlosrfernandez,項目名稱:ReactiveTraderCloud,代碼行數:15,代碼來源:connection.ts


注:本文中的rxjs/Rx.Subscription.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。