Skip to content

Commit

Permalink
Merge pull request #4 from lukepistrol/fix/sendable-reloaded
Browse files Browse the repository at this point in the history
Fixes: #3: mark closure of task modifier with `@MainActor`
  • Loading branch information
lukepistrol authored Sep 20, 2023
2 parents 17e002b + 5ad34b2 commit 4be5587
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/TaskTrigger/View+Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension View {
/// - action: An async action to perform whenever the trigger fires.
func task(
_ trigger: Binding<PlainTaskTrigger>,
_ action: @escaping @Sendable () async -> Void
_ action: @escaping @Sendable @MainActor () async -> Void
) -> some View {
modifier(TaskTriggerViewModifier(trigger: trigger, action: { _ in await action() }))
}
Expand Down
2 changes: 0 additions & 2 deletions TaskTriggerDemo/TaskTriggerDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ struct ContentView: View {
operation like a network call or some other (possibly) expensive operation.
*/

@MainActor
private func setRandomNumber(_ value: Int) async {
try? await Task.sleep(for: .seconds(1))
if Task.isCancelled { return }
self.randomNumber = value
}

@MainActor
private func resetToZero() async {
try? await Task.sleep(for: .seconds(1))
if Task.isCancelled { return }
Expand Down

0 comments on commit 4be5587

Please sign in to comment.