Skip to content

Commit 07cd0c2

Browse files
authored
Add priority to async fireAndForget. (#1084)
* Add priority to async fireAndForget. * actually use priority
1 parent 0adbc62 commit 07cd0c2

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,6 @@ public struct Effect<Output, Failure: Error>: Publisher {
260260
.eraseToEffect()
261261
}
262262

263-
/// Creates an effect that executes some work in the real world that doesn't need to feed data
264-
/// back into the store.
265-
///
266-
/// - Parameter work: A closure encapsulating some work to execute in the real world.
267-
/// - Returns: An effect.
268-
public static func fireAndForget(_ work: @escaping @Sendable () async -> Void) -> Effect {
269-
Effect<Void, Never>.task { await work() }
270-
.fireAndForget()
271-
}
272-
273263
/// Transforms all elements from the upstream effect with a provided closure.
274264
///
275265
/// - Parameter transform: A closure that transforms the upstream effect's output to a new output.

Sources/ComposableArchitecture/Effects/Concurrency.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,21 @@ import SwiftUI
102102
}
103103
.eraseToEffect()
104104
}
105+
106+
/// Creates an effect that executes some work in the real world that doesn't need to feed data
107+
/// back into the store.
108+
///
109+
/// - Parameters:
110+
/// - priority: Priority of the underlying task. If `nil`, the priority will come from
111+
/// `Task.currentPriority`.
112+
/// - work: A closure encapsulating some work to execute in the real world.
113+
/// - Returns: An effect.
114+
public static func fireAndForget(
115+
priority: TaskPriority? = nil,
116+
_ work: @escaping @Sendable () async -> Void
117+
) -> Effect {
118+
Effect<Void, Never>.task(priority: priority) { await work() }
119+
.fireAndForget()
120+
}
105121
}
106122
#endif

0 commit comments

Comments
 (0)