forked from PekanMmd/Pokemon-XD-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XGThreadManager.swift
57 lines (40 loc) · 1.18 KB
/
XGThreadManager.swift
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
//
// XGThreadManager.swift
// GoD Tool
//
// Created by The Steez on 26/10/2018.
//
import Foundation
// About time I added background threads!
class XGThreadManager {
// thought I'd make a singleton object just for the banter
static let manager = XGThreadManager()
// Wow, recent swift versions have really streamlined the whole multi threading process
// This is about all I really need
// Just need to make sure I put stuff on the right queues
// Remember all UI stuff should go on the main queue
func runInBackgroundAsync(_ closure: @escaping () -> Void) {
let dispatchQueue = DispatchQueue(label: "GoDBackgroundQueueAsync", qos: .background)
dispatchQueue.async {
closure()
}
}
func runInBackgroundSync(_ closure: @escaping () -> Void) {
let dispatchQueue = DispatchQueue(label: "GoDBackgroundQueueSync", qos: .background)
dispatchQueue.sync {
closure()
}
}
func runInForegroundAsync(_ closure: @escaping () -> Void) {
let dispatchQueue = DispatchQueue.main
dispatchQueue.async {
closure()
}
}
func runInForegroundSync(_ closure: @escaping () -> Void) {
let dispatchQueue = DispatchQueue.main
dispatchQueue.sync {
closure()
}
}
}