forked from getsentry/sentry-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invocations.swift
49 lines (39 loc) · 1.02 KB
/
Invocations.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
import Foundation
/**
* For recording invocations of methods in a list in a thread safe manner.
*/
public class Invocations<T> {
public init() {}
private let queue = DispatchQueue(label: "Invocations", attributes: .concurrent)
private var _invocations: [T] = []
public var invocations: [T] {
return queue.sync {
return self._invocations
}
}
public var count: Int {
return queue.sync {
return self._invocations.count
}
}
public var first: T? {
return queue.sync {
return self._invocations.first
}
}
public var last: T? {
return queue.sync {
return self._invocations.last
}
}
public var isEmpty: Bool {
return queue.sync {
return self._invocations.isEmpty
}
}
public func record(_ invocation: T) {
queue.async(flags: .barrier) {
self._invocations.append(invocation)
}
}
}