本文整理匯總了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');
});