@@ -12,7 +12,7 @@ private let pollLeeway = NimbleTimeInterval.milliseconds(1)
12
12
13
13
// Like PollResult, except it doesn't support objective-c exceptions.
14
14
// Which is tolerable because Swift Concurrency doesn't support recording objective-c exceptions.
15
- internal enum AsyncPollResult < T> {
15
+ internal enum AsyncPollResult < T: Sendable > : Sendable {
16
16
/// Incomplete indicates None (aka - this value hasn't been fulfilled yet)
17
17
case incomplete
18
18
/// TimedOut indicates the result reached its defined timeout limit before returning
@@ -57,10 +57,10 @@ internal enum AsyncPollResult<T> {
57
57
// Inspired by swift-async-algorithm's AsyncChannel, but massively simplified
58
58
// especially given Nimble's usecase.
59
59
// AsyncChannel: https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/Channels/AsyncChannel.swift
60
- internal actor AsyncPromise < T> {
60
+ internal actor AsyncPromise < T: Sendable > {
61
61
private let storage = Storage ( )
62
62
63
- private final class Storage {
63
+ private final class Storage : @ unchecked Sendable {
64
64
private var continuations : [ UnsafeContinuation < T , Never > ] = [ ]
65
65
private var value : T ?
66
66
// Yes, this is not the fastest lock, but it's platform independent,
@@ -131,7 +131,7 @@ internal actor AsyncPromise<T> {
131
131
/// checked.
132
132
///
133
133
/// In addition, stopping the run loop is used to halt code executed on the main run loop.
134
- private func timeout< T> ( timeoutQueue: DispatchQueue , timeoutInterval: NimbleTimeInterval , forcefullyAbortTimeout: NimbleTimeInterval ) async -> AsyncPollResult < T > {
134
+ private func timeout< T: Sendable > ( timeoutQueue: DispatchQueue , timeoutInterval: NimbleTimeInterval , forcefullyAbortTimeout: NimbleTimeInterval ) async -> AsyncPollResult < T > {
135
135
do {
136
136
try await Task . sleep ( nanoseconds: timeoutInterval. nanoseconds)
137
137
} catch { }
@@ -165,7 +165,7 @@ private func timeout<T>(timeoutQueue: DispatchQueue, timeoutInterval: NimbleTime
165
165
return await promise. value
166
166
}
167
167
168
- private func poll( _ pollInterval: NimbleTimeInterval , expression: @escaping ( ) async throws -> PollStatus ) async -> AsyncPollResult < Bool > {
168
+ private func poll( _ pollInterval: NimbleTimeInterval , expression: @escaping @ Sendable ( ) async throws -> PollStatus ) async -> AsyncPollResult < Bool > {
169
169
for try await _ in AsyncTimerSequence ( interval: pollInterval) {
170
170
do {
171
171
if case . finished( let result) = try await expression ( ) {
@@ -199,7 +199,7 @@ private func runPoller(
199
199
pollInterval: NimbleTimeInterval ,
200
200
awaiter: Awaiter ,
201
201
fnName: String = #function, file: FileString = #file, line: UInt = #line,
202
- expression: @escaping ( ) async throws -> PollStatus
202
+ expression: @escaping @ Sendable ( ) async throws -> PollStatus
203
203
) async -> AsyncPollResult < Bool > {
204
204
awaiter. waitLock. acquireWaitingLock (
205
205
fnName,
@@ -258,7 +258,7 @@ private func runAwaitTrigger<T>(
258
258
timeoutInterval: NimbleTimeInterval ,
259
259
leeway: NimbleTimeInterval ,
260
260
file: FileString , line: UInt ,
261
- _ closure: @escaping ( @escaping ( T ) -> Void ) async throws -> Void
261
+ _ closure: @escaping @ Sendable ( @escaping @ Sendable ( T ) -> Void ) async throws -> Void
262
262
) async -> AsyncPollResult < T > {
263
263
let timeoutQueue = awaiter. timeoutQueue
264
264
let completionCount = Box ( value: 0 )
@@ -309,7 +309,7 @@ internal func performBlock<T>(
309
309
timeoutInterval: NimbleTimeInterval ,
310
310
leeway: NimbleTimeInterval ,
311
311
file: FileString , line: UInt ,
312
- _ closure: @escaping ( @escaping ( T ) -> Void ) async throws -> Void
312
+ _ closure: @escaping @ Sendable ( @escaping @ Sendable ( T ) -> Void ) async throws -> Void
313
313
) async -> AsyncPollResult < T > {
314
314
await runAwaitTrigger (
315
315
awaiter: NimbleEnvironment . activeInstance. awaiter,
@@ -324,7 +324,7 @@ internal func pollBlock(
324
324
file: FileString ,
325
325
line: UInt ,
326
326
fnName: String = #function,
327
- expression: @escaping ( ) async throws -> PollStatus ) async -> AsyncPollResult < Bool > {
327
+ expression: @escaping @ Sendable ( ) async throws -> PollStatus ) async -> AsyncPollResult < Bool > {
328
328
await runPoller (
329
329
timeoutInterval: timeoutInterval,
330
330
pollInterval: pollInterval,
0 commit comments