EG
await sleep(3000);
console.log(1);
await sleep(2500);
console.log(2);
await sleep(300);
console.log(3)
Size: a a a
EG
L
Observable.create(function(observer) {
setTimeout(() => observer.next(1), 3000)
setTimeout(() => observer.next(2), 2500)
setTimeout(() => observer.next(3), 300)
setTimeout(() => observer.next(1), 0)
});L
L
EG
L
R
R
L
R
L
L
R
L
some.service.ts
class SomeService {
checkOrValidate(data: ISomeData) {
return this.http
.get('url)
.delay(500)
.map(() => res).map(() => validate with data)
}
component:
fb.group({ field: [ '', [Validators .... ], [ this.validateSmth.bind(this)]
validateSmth(control: AbstractControl) { return this.someService.checkOrValidate(control.value) -> logic
Вキ
function randomDelay<T>(
min: number, max: number
): MonoTypeOperatorFunction<T> {
return concatMap(
value => of(value).pipe(
delay(getRandom(min, max))
)
);
}
source.pipe(
randomDelay(100, 1000)
)
L
function randomDelay<T>(
min: number, max: number
): MonoTypeOperatorFunction<T> {
return concatMap(
value => of(value).pipe(
delay(getRandom(min, max))
)
);
}
source.pipe(
randomDelay(100, 1000)
)
Вキ
EG
function randomDelay<T>(
min: number, max: number
): MonoTypeOperatorFunction<T> {
return concatMap(
value => of(value).pipe(
delay(getRandom(min, max))
)
);
}
source.pipe(
randomDelay(100, 1000)
)
EG
Вキ
function delaySync<T>(
time: number
): MonoTypeOperatorFunction<T> {
return concatMap(pipe(of, delay(time)));
}
source.pipe(
delaySync(100),
tap(() => console.log(1)),
delaySync(1000),
tap(() => console.log(2)),
)