30
30
public struct ConditionalInterceptor < Interceptor: Sendable > : Sendable {
31
31
public struct Subject : Sendable {
32
32
33
- private let predicate : @Sendable ( MethodDescriptor ) -> Bool
33
+ private let predicate : @Sendable ( _ descriptor : MethodDescriptor ) -> Bool
34
34
35
35
/// An operation subject specifying an interceptor that applies to all RPCs across all services will be registered with this client.
36
36
public static var all : Self {
37
- Self ( predicate : { _ in true } )
37
+ Self { _ in true }
38
38
}
39
39
40
40
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified services.
41
41
///
42
42
/// - Parameters:
43
43
/// - services: The list of service descriptors for which this interceptor should intercept RPCs.
44
44
public static func services( _ services: Set < ServiceDescriptor > ) -> Self {
45
- Self ( predicate : { descriptor in
45
+ Self { descriptor in
46
46
services. contains ( descriptor. service)
47
- } )
47
+ }
48
48
}
49
49
50
50
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified service methods.
51
51
///
52
52
/// - Parameters:
53
53
/// - methods: The list of method descriptors for which this interceptor should intercept RPCs.
54
54
public static func methods( _ methods: Set < MethodDescriptor > ) -> Self {
55
- Self ( predicate : { descriptor in
55
+ Self { descriptor in
56
56
methods. contains ( descriptor)
57
- } )
57
+ }
58
58
}
59
59
60
60
/// An operation subject specifying an interceptor that will be applied only to RPCs directed to the specified services or service methods.
61
61
///
62
62
/// - Parameters:
63
63
/// - services: The list of service descriptors for which this interceptor should intercept RPCs.
64
64
/// - methods: The list of method descriptors for which this interceptor should intercept RPCs.
65
+ @available ( gRPCSwift 2 . 2 , * )
65
66
public static func only(
66
67
services: Set < ServiceDescriptor > ,
67
68
methods: Set < MethodDescriptor >
68
69
) -> Self {
69
- Self ( predicate : { descriptor in
70
+ Self { descriptor in
70
71
services. contains ( descriptor. service) || methods. contains ( descriptor)
71
- } )
72
+ }
72
73
}
73
74
74
75
/// An operation subject specifying an interceptor that will be applied to all RPCs across all services for this client excluding the specified services or service methods.
75
76
///
76
77
/// - Parameters:
77
78
/// - services: The list of service descriptors for which this interceptor should **not** intercept RPCs.
78
79
/// - methods: The list of method descriptors for which this interceptor should **not** intercept RPCs.
80
+ @available ( gRPCSwift 2 . 2 , * )
79
81
public static func allExcluding(
80
82
services: Set < ServiceDescriptor > ,
81
83
methods: Set < MethodDescriptor >
82
84
) -> Self {
83
- Self ( predicate : { descriptor in
85
+ Self { descriptor in
84
86
!( services. contains ( descriptor. service) || methods. contains ( descriptor) )
85
- } )
87
+ }
86
88
}
87
89
88
90
/// An operation subject specifying an interceptor that will be applied to RPCs whose ``MethodDescriptor`` satisfies a `predicate`.
@@ -96,8 +98,9 @@ public struct ConditionalInterceptor<Interceptor: Sendable>: Sendable {
96
98
///
97
99
/// - Parameters:
98
100
/// - predicate: A `@Sendable` closure evaluated per RPC. Return `true` to intercept.
101
+ @available ( gRPCSwift 2 . 2 , * )
99
102
public static func allMatching(
100
- _ predicate: @Sendable @escaping ( MethodDescriptor ) -> Bool
103
+ _ predicate: @Sendable @escaping ( _ descriptor : MethodDescriptor ) -> Bool
101
104
) -> Self {
102
105
Self ( predicate: predicate)
103
106
}
0 commit comments