1. CurrentThreadScheduler
Represents the Scheduler of the current thread, the thread used by default. How does it get the current thread: Subscribe, for example
- If the correlation is too direct
CurrentThreadScheduler.instance.schedule(())
throughschedule()
callqueue
Retrieves and returns one using the current associated thread keyqueue
- If there is no association:
CurrentThreadScheduler.isScheduleRequired
throughisScheduleRequired
Set a thread scheduling key
Thread
Two methods for accessing thread scheduling keys are extended:Where, this is called when there is a current thread scheduling key
schedule()
, returns aScheduledItem
:ScheduledItem
The initialization process is savedstate
andaction
And finally theinvoke()
Is called when
2. MainScheduler
MainScheduler is the main thread, we need to perform some of the UI related operations will need to switch to the main thread, it is inherited from SerialDispatchQueueScheduler (serial), the initialization process saved a thread _mainQueue: DispatchQueue, this queue is the main thread self._mainqueue = dispatchqueue.main
3. SerialDispatchQueueScheduler
It encapsulates the GCD serial queue, if we need to perform some serial task, you can switch to the Scheduler, initialized by the configuration – > DispatchQueueConfiguration conducted a series of multithreading configuration:
4. ConcurrentDispatchQueueScheduler
It encapsulates the GCD parallel queue, if we need to perform some parallel tasks, you can switch to the Scheduler, initialized by the configuration – > DispatchQueueConfiguration conducted a series of multithreading configuration:
5. OperationQueueScheduler
NSOperation
configuration
DispatchQueueConfiguration
6. Easy to use
* SerialDispatchQueueScheduler
Copy the code
,2,3,4,5,6,7,8,9,10 observables. Of (1). ObserveOn (SerialDispatchQueueScheduler. Init (internalSerialQueueName:"observeOnSerial"))
.subscribe{print("observeOn".$0,Thread.current)}
.disposed(by: self.bag)
Copy the code
* ConcurrentDispatchQueueScheduler
Copy the code
Observable.of( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100) .subscribeOn(ConcurrentDispatchQueueScheduler.init(qos: .background)) .subscribe{print("subscribeOn".$0,Thread.current)}
.disposed(by: self.bag)
Copy the code
* OperationQueueScheduler
Copy the code
let opQueue = OperationQueue.init()
Observable.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)
.subscribeOn(OperationQueueScheduler.init(operationQueue: opQueue))
.subscribe{print("subscribeOn".$0,Thread.current)}
.disposed(by: self.bag)
Copy the code