This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createRxObservable() { | |
let source: Observable<Int> = Observable.interval(1, scheduler: ConcurrentDispatchQueueScheduler.init(qos: DispatchQoS.background)).take(3) | |
source | |
.subscribe(onNext: { number in | |
print("Second: ", number) | |
}, onError: { _ in print("On Error") }, | |
onCompleted: { print("Complete") }, | |
onDisposed: nil) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createRxObservable() { | |
let source = Observable<Int>.from([1, 2, 3, 4, 6, 7]) | |
source | |
.subscribe(onNext: { number in | |
print("Current emitted number: ", number) | |
}, onError: { _ in print("On Error") }, | |
onCompleted: { print("Complete") }, | |
onDisposed: nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createRxObservable() { | |
let source: Observable<Int> = Observable.deferred { | |
let source: Observable<Int> = Observable.create { observer in | |
for i in 1...5 { | |
observer.on(.next(i)) | |
} | |
observer.on(.completed) | |
return Disposables.create() | |
} | |
return source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createRxObservable() { | |
let source: Observable<Int> = Observable.create { observer in | |
for i in 1...5 { | |
observer.on(.next(i)) | |
} | |
observer.on(.completed) | |
return Disposables.create() | |
} | |
source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let group = DispatchGroup() | |
group.enter() | |
let dispatchQueue1 = DispatchQueue.init(label: "dispatchQueue") | |
dispatchQueue1.sync { | |
for i in 0..<5 { | |
print("DispatchQueue X ", i) | |
} | |
group.leave() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//With Different priority | |
let dispatchQueue1 = DispatchQueue(label: "Queue 1", qos: .userInteractive) | |
let dispatchQueue2 = DispatchQueue(label: "Queue 2", qos: .background) | |
dispatchQueue1.async { | |
for i in 0..<5 { | |
print("DispatchQueue X ", i) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dispatchQueue = DispatchQueue(label: "Background", attributes: .concurrent) | |
dispatchQueue.async { | |
for i in 0..<5 { | |
print("DispatchQueue X ", i) | |
} | |
} | |
dispatchQueue.async { | |
for i in 5..<10 { | |
print("DispatchQueue Y ", i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let operationQueue1 = OperationQueue.init() | |
let operation1 = BlockOperation.init() | |
operation1.addExecutionBlock { | |
print("I am operation execution block injected in the operation1") | |
} | |
operationQueue1.addOperation(operation1) | |
operationQueue1.addOperation { | |
print("I am operation execution block injected direct to queue by operation") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let operationQueue = OperationQueue() | |
let op0 = BlockOperation() | |
op0.completionBlock = { | |
print("op0 completionBlock") | |
} | |
op0.addExecutionBlock { | |
print("op0 executionBlock #1") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum OperationState: Int { | |
case ready | |
case executing | |
case finished | |
} | |
class CustomOperationBlock: Operation{ | |
private var state: OperationState! | |