本文整理汇总了TypeScript中rxjs.AsyncSubject.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AsyncSubject.subscribe方法的具体用法?TypeScript AsyncSubject.subscribe怎么用?TypeScript AsyncSubject.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.AsyncSubject
的用法示例。
在下文中一共展示了AsyncSubject.subscribe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: asyncSubject
asyncSubject() {
let asyncSubject$ = new AsyncSubject();
interval(300).pipe(
take(5)
)
.subscribe(asyncSubject$);
asyncSubject$.subscribe(val => console.log(`First async subject: ${val}`)); // 4 (only after 1.5sec)
// Subscribe after it will complete
setTimeout(() => {
asyncSubject$.subscribe(val => console.log(`Second async subject: ${val}`)) // 4
}, 2000);
}
示例2: setTimeout
setTimeout(() => {
asyncSubject$.subscribe(val => console.log(`Second async subject: ${val}`)) // 4
}, 2000);
示例3: setInterval
console.log(`do ${x}`);
})
.take(3);
source.subscribe(
(x)=>{console.log(`timer ${x}`)},
(error)=>console.log(`error ${error}`),
()=>console.log('complete')
)
var subject = new rx.AsyncSubject();
var i = 0;
var handle = setInterval(function () {
subject.next(i);
if (++i > 3) {
subject.complete();
clearInterval(handle);
}
}, 500);
var subscription = subject.subscribe(
function (x) {
console.log('Next: ' + x.toString());
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});