-
Notifications
You must be signed in to change notification settings - Fork 29
[Enhancement]Simplify Task.timeout
and Publisher.nextValue
#914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,47 +5,45 @@ | |||||
import Foundation | ||||||
|
||||||
/// An extension to the `Task` type that adds timeout functionality. | ||||||
extension Task where Failure == Error { | ||||||
/// An error type representing a timeout condition. | ||||||
enum TimeoutError: Error { | ||||||
/// Indicates that the operation has timed out. | ||||||
case timedOut | ||||||
} | ||||||
|
||||||
/// Initializes a new task with a timeout. | ||||||
/// | ||||||
/// This initializer creates a new task that will execute the given operation | ||||||
/// with a specified timeout. If the operation doesn't complete within the | ||||||
/// timeout period, a `TimeoutError` will be thrown. | ||||||
/// | ||||||
/// - Parameters: | ||||||
/// - timeout: The maximum duration (in seconds) to wait for the operation to complete. | ||||||
/// - operation: The asynchronous operation to perform. | ||||||
/// | ||||||
/// - Returns: A new `Task` instance that will execute the operation with the specified timeout. | ||||||
/// | ||||||
/// - Throws: `TimeoutError.timedOut` if the operation doesn't complete within the specified timeout. | ||||||
/// | ||||||
/// - Note: This implementation uses a task group to manage concurrent execution | ||||||
/// of the main operation and the timeout timer. | ||||||
extension Task where Failure == any Error { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constraint
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
@discardableResult | ||||||
init( | ||||||
timeout: TimeInterval, | ||||||
operation: @Sendable @escaping () async throws -> Success | ||||||
priority: TaskPriority? = nil, | ||||||
/// New: a timeout property to configure how long a task may perform before failing with a timeout error. | ||||||
timeoutInSeconds: TimeInterval, | ||||||
file: StaticString = #fileID, | ||||||
function: StaticString = #function, | ||||||
line: UInt = #line, | ||||||
operation: @Sendable @escaping @isolated(any) () async throws -> Success | ||||||
|
operation: @Sendable @escaping @isolated(any) () async throws -> Success | |
operation: @Sendable @escaping () async throws -> Success |
Copilot uses AI. Check for mistakes.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ final class MockRTCAudioStore { | |
audioStore = RTCAudioStore(session: session) | ||
} | ||
|
||
deinit { | ||
InjectedValues[\.audioStore] = .init() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a leftover from the other PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is actually here to clean the InjectedValues context when the store isn't needed any more. Now that i'm thinking out loud though, it will never be triggered as the reference is still in InjectedValues, so deinit will never be triggered. We probably need an explicit method to uninstall/dismantle. |
||
} | ||
|
||
/// We call this just before the object that needs to use the mock is about to be created. | ||
func makeShared() { | ||
RTCAudioStore.currentValue = audioStore | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
nonisolated(unsafe)
is potentially dangerous as it bypasses Swift's concurrency safety checks. Consider using a safer approach like capturingself
directly in the Task closure or using proper isolation.Copilot uses AI. Check for mistakes.