Skip to content

Commit 369fea5

Browse files
committed
🐛 Make blend of run to be run on MainActor
1 parent 9f0c855 commit 369fea5

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

Examples/Counter/Counter/Counter.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct Counter: Dripper {
1616

1717
// MARK: Nested Types
1818

19-
@MainActor
2019
@Observable
20+
@MainActor
2121
final class State: Sendable {
2222
var counter: Int = .zero
2323
var text = ""
@@ -43,11 +43,6 @@ struct Counter: Dripper {
4343
state.counter = .zero
4444
case .randomNumber:
4545
return .run { pour in
46-
func randomNumber() async throws -> Int {
47-
try await Task.sleep(for: .seconds(1))
48-
return Int.random(in: 1...100)
49-
}
50-
5146
let randomNumber = try await randomNumber()
5247

5348
pour(.decreaseCounter)
@@ -58,6 +53,13 @@ struct Counter: Dripper {
5853
return .none
5954
}
6055
}
56+
57+
// MARK: Functions
58+
59+
private func randomNumber() async throws -> Int {
60+
try await Task.sleep(for: .seconds(1))
61+
return Int.random(in: 1...100)
62+
}
6163
}
6264

6365
import SwiftUI

Sources/Dripper/Effect.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ extension Effect {
5050
// MARK: Static Functions
5151

5252
public static func run(
53-
blend: @escaping (_ pour: Pour<Action>) async throws -> Void,
54-
catch errorHandler: ((_ error: any Error, _ pour: Pour<Action>) async -> Void)? = nil,
53+
blend: @escaping @MainActor (_ pour: Pour<Action>) async throws -> Void,
54+
catch errorHandler: (@MainActor (_ error: any Error, _ pour: Pour<Action>) async -> Void)? = nil,
5555
fileID: StaticString = #fileID,
5656
line: UInt = #line
5757
) -> Self {

0 commit comments

Comments
 (0)