Skip to content

Commit a29176f

Browse files
Merge pull request #4768 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents b02542d + 8faef1a commit a29176f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

stdlib/public/Concurrency/TaskSleepDuration.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,20 @@ extension Task where Success == Never, Failure == Never {
142142
) async throws {
143143
try await clock.sleep(until: deadline, tolerance: tolerance)
144144
}
145+
146+
/// Suspends the current task for the given duration on a continuous clock.
147+
///
148+
/// If the task is cancelled before the time ends, this function throws
149+
/// `CancellationError`.
150+
///
151+
/// This function doesn't block the underlying thread.
152+
///
153+
/// try await Task.sleep(for: .seconds(3))
154+
///
155+
/// - Parameter duration: The duration to wait.
156+
@available(SwiftStdlib 5.7, *)
157+
@_alwaysEmitIntoClient
158+
public static func sleep(for duration: Duration) async throws {
159+
try await sleep(until: .now + duration, clock: .continuous)
160+
}
145161
}

0 commit comments

Comments
 (0)