timeout

signature: timeout(due: number, scheduler: Scheduler): Observable

지정된 기간 전에 값이 방출되지 않는 경우, 에러를 발생

예시

예시 1: 2.5초 뒤에 Timeout

( StackBlitz | jsBin | jsFiddle )

// RxJS v6+
import { of } from 'rxjs';
import { concatMap, timeout, catchError, delay } from 'rxjs/operators';

// 요청을 수행하는 함수
function makeRequest(timeToDelay) {
  return of('Request Complete!').pipe(delay(timeToDelay));
}

of(4000, 3000, 2000)
  .pipe(
    concatMap(duration =>
      makeRequest(duration).pipe(
        timeout(2500),
        catchError(error => of(`Request timed out after: ${duration}`))
      )
    )
  )
  /*
   *  "Request timed out after: 4000"
   *  "Request timed out after: 3000"
   *  "Request Complete!"
   */
  .subscribe(val => console.log(val));

추가 자료

📂 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/timeout.ts

Last updated