本文整理汇总了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
})
示例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
)
)
}
})
示例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)
}