Skip to content

Instantly share code, notes, and snippets.

@torpedo87
Created January 21, 2019 11:16
Show Gist options
  • Save torpedo87/9515b1627df755520dcdce7f5363c94b to your computer and use it in GitHub Desktop.
Save torpedo87/9515b1627df755520dcdce7f5363c94b to your computer and use it in GitHub Desktop.
scheduler

scheduler

  • 프로세스가 발생하는 컨텍스트(쓰레드, 디스패치큐 등)
  • cold observable은 구독을 해야 이벤트를 방출하는 시퀀스로서 구독하기 전에는 아무것도 생성하지 않으므로 컨텍스트가 설정되어 있지 않은 상태로서 subscribeOn 이 유효
  • hot observable은 구독 전에도 이미 이벤트를 방출하고 있는 시퀀스로서 이미 컨텍스트가 있으며 RxSwift가 이를 통제할 수 없으므로 subscribeOn 이 소용없음

subscribeOn

  • Wraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler.
  • 구독 이전 연산자들의 클로저가 실행되는 장소를 지정
  • 원래는 자동으로 현재 스레드에서 시퀀스가 이벤트를 방출, 가공하나 이 연산자를 통해 바꿀 수 있다

observeOn

  • Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
  • subscribe 의 클로저가 실행되는 장소를 지정
  • 구독해서 받은 데이터들을 처리하는 스케줄러를 변경

SerialDispatchQueueScheduler

  • Abstracts the work that needs to be performed on a specific dispatch_queue_t. It will make sure that even if concurrent dispatch queue is passed, it’s transformed into a serial one.
  • observeOn 에 최적화 되어 있다
  • process background jobs which are better scheduled in a serial manner

ConcurrentDispatchQueueScheduler

  • Abstracts the work that needs to be performed on a specific dispatch_queue_t. You can also pass a serial dispatch queue, it shouldn’t cause any problems.
  • multiple, long-running tasks that need to end simultaneously

OperationQueueScheduler

  • Abstracts the work that needs to be performed on a specific NSOperationQueue.
  • concurrent task를 좀더 세밀하게 해야할 때 maxConcurrentOperationCount 설정 가능
  • This scheduler is suitable for cases when there is some bigger chunk of work that needs to be performed in background and you want to fine tune concurrent processing using maxConcurrentOperationCount

TestScheduler

  • RxTest 라이브러리
  • 테스트할 때에만 사용
  • cold observable은 200 이후에 시작
  • hot observable은 바로 시작
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment