本文整理汇总了TypeScript中rxjs/operators.retry函数的典型用法代码示例。如果您正苦于以下问题:TypeScript retry函数的具体用法?TypeScript retry怎么用?TypeScript retry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了retry函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: retry1
retry1() {
// emit value every 1s
const source = interval(1000);
const example = source.pipe(
mergeMap(val => {
// throw error for demonstration
if (val > 5) {
return throwError('Error!');
}
return of(val);
}),
// retry 2 times on error
retry(2)
);
/*
output:
0..1..2..3..4..5..
0..1..2..3..4..5..
0..1..2..3..4..5..
"Error!: Retried 2 times then quit!"
*/
const subscribe = example.subscribe({
next: val => console.log(val),
error: val => console.log(`${val}: Retried 2 times then quit!`)
});
}
示例2: switchMap
switchMap(() =>
fetchServicePlans(parent.id).pipe(
retry(2),
map(({ response }) => response),
map((plans: string[]) => {
return plans.map(name => ({ name }));
})
)
示例3: it
it('should retry just fine', () => {
const e1 = cold('---a--b--c--d--e--#');
const e1subs = ['^ ! ',
' ^ !'];
const expected = '---a--b--c--d--e-----a--b--c--d--e--#';
expectObservable(e1.pipe(share(), retry(1))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例4: it
it('should return a never observable given an async just-throw source and no count', () => {
const source = cold('-#'); // important that it's not a sync error
const unsub = ' !';
const expected = '--------------------------------------';
const result = source.pipe(retry());
expectObservable(result, unsub).toBe(expected);
});
示例5: it
it('overrides protractor specs', (done) => {
host.scopedSync().rename(normalize('./e2e/app.e2e-spec.ts'),
normalize('./e2e/renamed-app.e2e.spec.ts'));
const overrides = { specs: ['./e2e/renamed-app.e2e.spec.ts'] };
runTargetSpec(host, protractorTargetSpec, overrides).pipe(
retry(3),
).toPromise().then(done, done.fail);
}, 60000);
示例6: linuxOnlyIt
linuxOnlyIt('overrides protractor specs', (done) => {
host.scopedSync().rename(normalize('./e2e/app.e2e-spec.ts'),
normalize('./e2e/renamed-app.e2e-spec.ts'));
const overrides = { specs: ['./e2e/renamed-app.e2e-spec.ts'] };
runTargetSpec(host, protractorTargetSpec, overrides).pipe(
retry(3),
).subscribe(undefined, done.fail, done);
}, 60000);
示例7: of
observable1 = constructorZone1.run(() => {
return of(1, 2, 3).pipe(
map((n: number) => {
expect(Zone.current.name).toEqual(constructorZone1.name);
if (n === 2) {
throw error;
}
return n;
}),
retry(1));
});
示例8: cold
'unsubscribed early', () => {
const source = cold('--1-2-3-#');
const unsub = ' ! ';
const subs = ['^ ! ',
' ^ ! '];
const expected = '--1-2-3---1-2-';
const result = source.pipe(retry(3));
expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});