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