 //  Copyright © 2016 Gavan Chan. All rights reserved.
 
+import Foundation
 import RxCocoa
 import RxSwift
 import UIKit


      let disposable: Disposable = transitions
        .observeOn(MainScheduler.asyncInstance)
        .spacingSamples(by: 2.0, on: MainScheduler.asyncInstance)
        .subscribe { [weak self] in self?.perform(transition: $0) }

      transitionDisposableKey = disposables.insert(disposable)


    return Observable<UIViewController>.create { observer in

      var disposed: Bool = false

      func dispatch(_ work: @escaping (() -> Void)) {
        if !disposed { DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: work) }
      }

      let restart: (() -> Void) = {
        let restart: UIViewController = PlaceholderActionViewController(withPlaceholderText: "Lorem Ipsum.", buttonText: "Restart") { [unowned self] in
          self.contentProducer = self.testObservable
        }
        observer.onNext(restart)
        observer.onCompleted()
      }

      let quxBaz: (() -> Void) = {
        let quxBaz: UIViewController = PlaceholderTextViewController(with: "Qux Baz...!")
        observer.onNext(quxBaz)
        dispatch(restart)
      }

      let fooBar: (() -> Void) = {
        let fooBar: UIViewController = PlaceholderTextViewController(with: "Foo Bar?!")
        observer.onNext(fooBar)
        dispatch(quxBaz)
      }

      DispatchQueue.main.async {
        let helloWorld: UIViewController = PlaceholderTextViewController(with: "Hello World!")
        observer.onNext(helloWorld)
        dispatch(fooBar)
      }

      return Disposables.create { disposed = true }

    }.map(Optional.init)

