0001    //
0002    //  Observable+Concurrency.swift
0003    //  Rx
0004    //
0005    //  Created by Krunoslav Zaher on 3/15/15.
0006    //  Copyright © 2015 Krunoslav Zaher. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    // MARK: observeOn
0012    
0013    extension ObservableType {
0014        
0015        /**
0016        Wraps the source sequence in order to run its observer callbacks on the specified scheduler.
0017        
0018        This only invokes observer callbacks on a `scheduler`. In case the subscription and/or unsubscription
0019        actions have side-effects that require to be run on a scheduler, use `subscribeOn`.
0020    
0021        - seealso: [observeOn operator on reactivex.io](http://reactivex.io/documentation/operators/observeon.html)
0022        
0023        - parameter scheduler: Scheduler to notify observers on.
0024        - returns: The source sequence whose observations happen on the specified scheduler.
0025        */
0026        @warn_unused_result(message="http://git.io/rxs.uo")
0027        public func observeOn(scheduler: ImmediateSchedulerType)
0028            -> Observable<E> {
0029            if let scheduler = scheduler as? SerialDispatchQueueScheduler {
0030                return ObserveOnSerialDispatchQueue(source: self.asObservable(), scheduler: scheduler)
0031            }
0032            else {
0033                return ObserveOn(source: self.asObservable(), scheduler: scheduler)
0034            }
0035        }
0036    }
0037    
0038    // MARK: subscribeOn
0039    
0040    extension ObservableType {
0041        
0042        /**
0043        Wraps the source sequence in order to run its subscription and unsubscription logic on the specified 
0044        scheduler. 
0045        
0046        This operation is not commonly used.
0047        
0048        This only performs the side-effects of subscription and unsubscription on the specified scheduler. 
0049        
0050        In order to invoke observer callbacks on a `scheduler`, use `observeOn`.
0051    
0052        - seealso: [subscribeOn operator on reactivex.io](http://reactivex.io/documentation/operators/subscribeon.html)
0053        
0054        - parameter scheduler: Scheduler to perform subscription and unsubscription actions on.
0055        - returns: The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
0056        */
0057        @warn_unused_result(message="http://git.io/rxs.uo")
0058        public func subscribeOn(scheduler: ImmediateSchedulerType)
0059            -> Observable<E> {
0060            return SubscribeOn(source: self, scheduler: scheduler)
0061        }
0062    }