forked from mike123789-dev/APIKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallbackQueue.swift
More file actions
38 lines (30 loc) · 1.02 KB
/
Copy pathCallbackQueue.swift
File metadata and controls
38 lines (30 loc) · 1.02 KB
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
import Foundation
/// `CallbackQueue` represents queue where `handler` of `Session.send(_:handler:)` runs.
public enum CallbackQueue {
/// Dispatches callback closure on main queue asynchronously.
case main
/// Dispatches callback closure on the queue where backend adapter callback runs.
case sessionQueue
/// Dispatches callback closure on associated operation queue.
case operationQueue(OperationQueue)
/// Dispatches callback closure on associated dispatch queue.
case dispatchQueue(DispatchQueue)
public func execute(closure: @escaping () -> Void) {
switch self {
case .main:
DispatchQueue.main.async {
closure()
}
case .sessionQueue:
closure()
case .operationQueue(let operationQueue):
operationQueue.addOperation {
closure()
}
case .dispatchQueue(let dispatchQueue):
dispatchQueue.async {
closure()
}
}
}
}