Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxSwift Scheduler

RxSwift Scheduler

USAMI Kosuke

August 20, 2018
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. ྫ hogeObservable .subscribeOn(hogeScheduler) .do(onNext: { _ in // hogeScheduler Ͱಈ࡞͢Δ

    } .observeOn(MainScheduler.instance) .subscribe(onNext: { _ in // ϝΠϯεϨουͰಈ࡞͢Δ })
  2. εϨου੍ޚ·ͱΊ • subscribeOn : Πϕϯτൃੜݩͷεέδϡʔϥࢦఆ • Web API ࣮ߦεϨουͷࢦఆ •

    σʔλϕʔεΞΫηεεϨουͷࢦఆ • observeOn : Πϕϯτॲཧͷεέδϡʔϥͷࢦఆ • UI ॲཧεϨουͷࢦఆ
  3. ྫɿ੾Γସ͑Ͱ͖ͳ͍έʔε let hogeRelay = BehaviorRelay(value: "A") let hogeThread = Thread()

    { sleep(1) hogeRelay.accept("B") sleep(1) hogeRelay.accept("C") } hogeThread.start()
  4. ྫɿ੾Γସ͑Ͱ͖ͳ͍έʔε hogeRelay .subscribeOn(MainScheduler.instance) .do(onNext: { _ in // hogeThread Ͱ

    accept ͨ͠΋ͷ͸ hogeThread Ͱಈ࡞ } .observeOn(MainScheduler.instance) .subscribe(onNext: { _ in // ϝΠϯεϨουͰಈ࡞͢Δ })
  5. Observable ͷ෼ྨ : Hot / Cold • Hot • subscribe

    ͠ͳͯ͘΋ετϦʔϜ͕ྲྀΕΔ • subscribeOn Ͱ੍ޚͰ͖ͳ͍ • Cold • subscribe ͨ͠ΒετϦʔϜ͕ྲྀΕग़͢ • subscribeOn Ͱ੍ޚͰ͖Δ
  6. ͲΕ͕ Hot ͰͲΕ͕ Cold ͔ʁ • Hot • Subject ΍

    Relay • Rx ͷ֎ଆ͔ΒετϦʔϜʹΠϕϯτΛૹΕΔ • Cold • ্هҎ֎͸͍͍ͩͨ Cold • Rx ͷ੍ޚԼʹ͋Δ