Skip to content

Commit

Permalink
🐛 Make blend of run to be run on MainActor
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyJunnos committed Oct 9, 2024
1 parent 9f0c855 commit 369fea5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Examples/Counter/Counter/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct Counter: Dripper {

// MARK: Nested Types

@MainActor
@Observable
@MainActor
final class State: Sendable {
var counter: Int = .zero
var text = ""
Expand All @@ -43,11 +43,6 @@ struct Counter: Dripper {
state.counter = .zero
case .randomNumber:
return .run { pour in
func randomNumber() async throws -> Int {
try await Task.sleep(for: .seconds(1))
return Int.random(in: 1...100)
}

let randomNumber = try await randomNumber()

pour(.decreaseCounter)
Expand All @@ -58,6 +53,13 @@ struct Counter: Dripper {
return .none
}
}

// MARK: Functions

private func randomNumber() async throws -> Int {
try await Task.sleep(for: .seconds(1))
return Int.random(in: 1...100)
}
}

import SwiftUI
Expand Down
4 changes: 2 additions & 2 deletions Sources/Dripper/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ extension Effect {
// MARK: Static Functions

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

0 comments on commit 369fea5

Please sign in to comment.