Skip to content

Commit 9fed867

Browse files
authored
copy edit Schedulers.md
1 parent 49ccdac commit 9fed867

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

Documentation/Schedulers.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,65 @@ Schedulers
55
1. [Custom schedulers](#custom-schedulers)
66
1. [Builtin schedulers](#builtin-schedulers)
77

8-
Schedulers abstract away mechanism for performing work.
8+
Schedulers abstract away the mechanism for performing work.
99

10-
Different mechanisms for performing work include, current thread, dispatch queues, operation queues, new threads, thread pools, run loops ...
10+
Different mechanisms for performing work include the current thread, dispatch queues, operation queues, new threads, thread pools, and run loops.
1111

12-
There are two main operators that work with schedulers. `observeOn` and `subscribeOn`.
12+
There are two main operators that work with schedulers, `observeOn` and `subscribeOn`.
1313

14-
If you want to perform work on different scheduler just use `observeOn(scheduler)` operator.
14+
If you want to perform work on a different scheduler just use `observeOn(scheduler)` operator.
1515

1616
You would usually use `observeOn` a lot more often then `subscribeOn`.
1717

18-
In case `observeOn` isn't explicitly specified, work will be performed on which ever thread/scheduler elements are generated.
18+
In case `observeOn` isn't explicitly specified, work will be performed on whichever thread/scheduler elements are generated.
1919

20-
Example of using `observeOn` operator
20+
Example of using the `observeOn` operator:
2121

2222
```
2323
sequence1
2424
.observeOn(backgroundScheduler)
2525
.map { n in
26-
print("This is performed on background scheduler")
26+
print("This is performed on the background scheduler")
2727
}
2828
.observeOn(MainScheduler.instance)
2929
.map { n in
30-
print("This is performed on main scheduler")
30+
print("This is performed on the main scheduler")
3131
}
3232
```
3333

3434
If you want to start sequence generation (`subscribe` method) and call dispose on a specific scheduler, use `subscribeOn(scheduler)`.
3535

36-
In case `subscribeOn` isn't explicitly specified, `subscribe` method will be called on the same thread/scheduler that `subscribeNext` or `subscribe` is called.
36+
In case `subscribeOn` isn't explicitly specified, the `subscribe` method will be called on the same thread/scheduler on which `subscribeNext` or `subscribe` is called.
3737

38-
In case `subscribeOn` isn't explicitly specified, `dispose` method will be called on the same thread/scheduler that initiated disposing.
38+
In case `subscribeOn` isn't explicitly specified, the `dispose` method will be called on the same thread/scheduler that initiated disposing.
3939

4040
In short, if no explicit scheduler is chosen, those methods will be called on current thread/scheduler.
4141

4242
# Serial vs Concurrent Schedulers
4343

4444
Since schedulers can really be anything, and all operators that transform sequences need to preserve additional [implicit guarantees](GettingStarted.md#implicit-observable-guarantees), it is important what kind of schedulers are you creating.
4545

46-
In case scheduler is concurrent, Rx's `observeOn` and `subscribeOn` operators will make sure everything works perfect.
46+
In case the scheduler is concurrent, Rx's `observeOn` and `subscribeOn` operators will make sure everything works perfectly.
4747

4848
If you use some scheduler that for which Rx can prove that it's serial, it will able to perform additional optimizations.
4949

50-
So far it only performing those optimizations for dispatch queue schedulers.
50+
So far it only performs those optimizations for dispatch queue schedulers.
5151

52-
In case of serial dispatch queue schedulers `observeOn` is optimized to just a simple `dispatch_async` call.
52+
In case of serial dispatch queue schedulers, `observeOn` is optimized to just a simple `dispatch_async` call.
5353

5454
# Custom schedulers
5555

5656
Besides current schedulers, you can write your own schedulers.
5757

58-
If you just want to describe who needs to perform work immediately, you can create your own scheduler by implementing `ImmediateScheduler` protocol.
58+
If you just want to describe who needs to perform work immediately, you can create your own scheduler by implementing the `ImmediateScheduler` protocol.
5959

6060
```swift
6161
public protocol ImmediateScheduler {
6262
func schedule<StateType>(state: StateType, action: (/*ImmediateScheduler,*/ StateType) -> RxResult<Disposable>) -> RxResult<Disposable>
6363
}
6464
```
6565

66-
If you want to create new scheduler that supports time based operations, then you'll need to implement.
66+
If you want to create a new scheduler that supports time based operations, then you'll need to implement the `Scheduler` protocol:
6767

6868
```swift
6969
public protocol Scheduler: ImmediateScheduler {
@@ -78,55 +78,55 @@ public protocol Scheduler: ImmediateScheduler {
7878
}
7979
```
8080

81-
In case scheduler only has periodic scheduling capabilities, you can inform Rx by implementing `PeriodicScheduler` protocol
81+
In case the scheduler only has periodic scheduling capabilities, you can inform Rx by implementing the `PeriodicScheduler` protocol:
8282

8383
```swift
8484
public protocol PeriodicScheduler : Scheduler {
8585
func schedulePeriodic<StateType>(state: StateType, startAfter: TimeInterval, period: TimeInterval, action: (StateType) -> StateType) -> RxResult<Disposable>
8686
}
8787
```
8888

89-
In case scheduler doesn't support `PeriodicScheduling` capabilities, Rx will emulate periodic scheduling transparently.
89+
In case the scheduler doesn't support `PeriodicScheduling` capabilities, Rx will emulate periodic scheduling transparently.
9090

9191
# Builtin schedulers
9292

9393
Rx can use all types of schedulers, but it can also perform some additional optimizations if it has proof that scheduler is serial.
9494

95-
These are currently supported schedulers
95+
These are the currently supported schedulers:
9696

9797
## CurrentThreadScheduler (Serial scheduler)
9898

9999
Schedules units of work on the current thread.
100100
This is the default scheduler for operators that generate elements.
101101

102-
This scheduler is also sometimes called `trampoline scheduler`.
102+
This scheduler is also sometimes called a "trampoline scheduler".
103103

104-
If `CurrentThreadScheduler.instance.schedule(state) { }` is called for first time on some thread, scheduled action will be executed immediately and hidden queue will be created where all recursively scheduled actions will be temporarily enqueued.
104+
If `CurrentThreadScheduler.instance.schedule(state) { }` is called for the first time on some thread, the scheduled action will be executed immediately and a hidden queue will be created where all recursively scheduled actions will be temporarily enqueued.
105105

106-
If some parent frame on call stack is already running `CurrentThreadScheduler.instance.schedule(state) { }`, scheduled action will be enqueued and executed when currently running action and all previously enqueued actions have finished executing.
106+
If some parent frame on the call stack is already running `CurrentThreadScheduler.instance.schedule(state) { }`, the scheduled action will be enqueued and executed when the currently running action and all previously enqueued actions have finished executing.
107107

108108
## MainScheduler (Serial scheduler)
109109

110-
Abstracts work that needs to be performed on `MainThread`. In case `schedule` methods are called from main thread, it will perform action immediately without scheduling.
110+
Abstracts work that needs to be performed on `MainThread`. In case `schedule` methods are called from main thread, it will perform the action immediately without scheduling.
111111

112112
This scheduler is usually used to perform UI work.
113113

114114
## SerialDispatchQueueScheduler (Serial scheduler)
115115

116-
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.
116+
Abstracts the work that needs to be performed on a specific `dispatch_queue_t`. It will make sure that even if a concurrent dispatch queue is passed, it's transformed into a serial one.
117117

118118
Serial schedulers enable certain optimizations for `observeOn`.
119119

120-
Main scheduler is an instance of `SerialDispatchQueueScheduler`.
120+
The main scheduler is an instance of `SerialDispatchQueueScheduler`.
121121

122122
## ConcurrentDispatchQueueScheduler (Concurrent scheduler)
123123

124124
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.
125125

126-
This scheduler is suitable when some work needs to be performed in background.
126+
This scheduler is suitable when some work needs to be performed in the background.
127127

128128
## OperationQueueScheduler (Concurrent scheduler)
129129

130130
Abstracts the work that needs to be performed on a specific `NSOperationQueue`.
131131

132-
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`.
132+
This scheduler is suitable for cases when there is some bigger chunk of work that needs to be performed in the background and you want to fine tune concurrent processing using `maxConcurrentOperationCount`.

0 commit comments

Comments
 (0)