本文整理汇总了TypeScript中rxjs.timer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript timer函数的具体用法?TypeScript timer怎么用?TypeScript timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timer函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should raises error when promise rejects', (done: MochaDone) => {
const e1 = concat(
of(1),
timer(10).pipe(mapTo(2)),
timer(10).pipe(mapTo(3)),
timer(100).pipe(mapTo(4))
);
const expected = [1, 2];
const error = new Error('error');
e1.pipe(
debounce((x: number) => {
if (x === 3) {
return new Promise((resolve: any, reject: any) => { reject(error); });
} else {
return new Promise((resolve: any) => { resolve(42); });
}
})
).subscribe((x: number) => {
expect(x).to.equal(expected.shift()); },
(err: any) => {
expect(err).to.be.an('error', 'error');
expect(expected.length).to.equal(0);
done();
}, () => {
done(new Error('should not be called'));
});
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:28,代码来源:debounce-spec.ts
示例2: combineLatest1
combineLatest1() {
// timerOne emits first value at 1s, then once every 4s
const timerOne = timer(1000, 4000);
// timerTwo emits first value at 2s, then once every 4s
const timerTwo = timer(2000, 4000);
// timerThree emits first value at 3s, then once every 4s
const timerThree = timer(3000, 4000);
// when one timer emits, emit the latest values from each timer as an array
const combined = combineLatest(timerOne, timerTwo, timerThree);
const subscribe = combined.subscribe(
([timerValOne, timerValTwo, timerValThree]) => {
/*
Example:
timerOne first tick: 'Timer One Latest: 1, Timer Two Latest:0, Timer Three Latest: 0
timerTwo first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 0
timerThree first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 1
*/
console.log(
`Timer One Latest: ${timerValOne},
Timer Two Latest: ${timerValTwo},
Timer Three Latest: ${timerValThree}`
);
}
);
}
开发者ID:zwvista,项目名称:SampleMisc,代码行数:27,代码来源:combining.service.ts
示例3: constructor
constructor() {
this.everySecond$ = timer(1000, 1000).pipe(
share(),
);
this.everyHalfSecond$ = timer(500, 500).pipe(
share(),
);
}
开发者ID:m-sc,项目名称:yamcs,代码行数:8,代码来源:Synchronizer.ts
示例4: it
it('should throttle events multiple times', () => {
const expected = ['1-0', '2-0'];
concat(
timer(0, 10, rxTestScheduler).pipe(take(3), map((x: number) => '1-' + x)),
timer(80, 10, rxTestScheduler).pipe(take(5), map((x: number) => '2-' + x))
).pipe(
throttleTime(50, rxTestScheduler)
).subscribe((x: string) => {
expect(x).to.equal(expected.shift());
});
rxTestScheduler.flush();
});
开发者ID:DallanQ,项目名称:rxjs,代码行数:13,代码来源:throttleTime-spec.ts
示例5: it
it('should emit a single value immediately', () => {
const dueTime = time('|');
const expected = '(x|)';
const source = timer(dueTime, rxTestScheduler);
expectObservable(source).toBe(expected, {x: 0});
});
开发者ID:deanius,项目名称:RxJS,代码行数:7,代码来源:timer-spec.ts
示例6: windowWhen1
windowWhen1() {
// emit immediately then every 1s
const source = timer(0, 1000);
const example = source.pipe(
// close window every 5s and emit observable of collected values from source
windowWhen(() => interval(5000)),
tap(_ => console.log('NEW WINDOW!'))
);
const subscribeTwo = example
.pipe(
// window emits nested observable
mergeAll()
/*
output:
"NEW WINDOW!"
0
1
2
3
4
"NEW WINDOW!"
5
6
7
8
9
*/
)
.subscribe(val => console.log(val));
}
开发者ID:zwvista,项目名称:SampleMisc,代码行数:31,代码来源:transforming.service.ts
示例7: of
const source = of(expiresAt).pipe(flatMap(expiration => {
const now = Date.now();
// Use the delay in a timer to
// run the refresh at the proper time
return timer(Math.max(1, expiresAt - now));
}));
开发者ID:pastorsj,项目名称:bannablog,代码行数:7,代码来源:authentication.service.ts
示例8: timer
registry.register('job-obs-async', createJobHandler<number, number, number>(arg => {
return timer(1).pipe(
take(3),
take(1),
map(() => arg + 1),
);
}));
开发者ID:angular,项目名称:angular-cli,代码行数:7,代码来源:simple-scheduler_spec.ts
示例9: observableTimer
.pipe(catchError((error : Error, source) => {
if (!shouldRetry(error)) {
throw error;
}
const currentError = error instanceof RequestError &&
isOfflineRequestError(error) ? ERROR_TYPES.OFFLINE : ERROR_TYPES.REGULAR;
const maxRetry = currentError === ERROR_TYPES.OFFLINE ?
maxRetryOffline : maxRetryRegular;
if (currentError !== lastError) {
retryCount = 0;
lastError = currentError;
}
if (++retryCount > maxRetry) {
throw error;
}
if (onRetry) {
onRetry(error, retryCount);
}
const delay = Math.min(
baseDelay * Math.pow(2, retryCount - 1),
maxDelay
);
const fuzzedDelay = getFuzzedDelay(delay);
return observableTimer(fuzzedDelay).pipe(
mergeMap(() => source));
}));
开发者ID:canalplus,项目名称:rx-player,代码行数:32,代码来源:backoff.ts
注:本文中的rxjs.timer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论