Skip to content

Commit df48b99

Browse files
author
Brandon Schoenfeld
committed
Revert "refactor: enable injecting a custom State type into Channel"
This reverts commit b1f6d55.
1 parent b587a1a commit df48b99

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

Sources/AsyncDataLoader/Channel/Channel.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
actor Channel<
2-
Success: Sendable,
3-
Failure: Error,
4-
ChannelState: Stateful
5-
>: Sendable where ChannelState.Success == Success, ChannelState.Failure == Failure {
6-
private var state: ChannelState
7-
8-
init(_ state: ChannelState) {
9-
self.state = state
10-
}
11-
}
12-
13-
extension Channel where ChannelState == State<Success, Failure> {
14-
/// Default initializer: uses DefaultState
15-
init() {
16-
self.init(State<Success, Failure>())
17-
}
1+
actor Channel<Success: Sendable, Failure: Error>: Sendable {
2+
private var state = State<Success, Failure>()
183
}
194

205
extension Channel {

Sources/AsyncDataLoader/Channel/State.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
typealias Waiter<Success, Failure> = CheckedContinuation<Success, Error>
22

3-
protocol Stateful: Actor {
4-
associatedtype Success: Sendable
5-
associatedtype Failure: Sendable
6-
7-
var waiters: [Waiter<Success, Failure>] { get set }
8-
var result: Success? { get set }
9-
var failure: Failure? { get set }
10-
11-
func setResult(result: Success) async
12-
func setFailure(failure: Failure) async
13-
func appendWaiters(waiters: Waiter<Success, Failure>...) async
14-
func removeAllWaiters() async
15-
}
16-
17-
actor State<Success, Failure>: Stateful {
3+
actor State<Success, Failure> {
184
var waiters = [Waiter<Success, Failure>]()
195
var result: Success?
206
var failure: Failure?

Sources/AsyncDataLoader/DataLoader.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public typealias BatchLoadFunction<Key: Hashable & Sendable, Value: Sendable> =
1010
@Sendable (_ keys: [Key]) async throws -> [DataLoaderValue<Value>]
1111
private typealias LoaderQueue<Key: Hashable & Sendable, Value: Sendable> = [(
1212
key: Key,
13-
channel: Channel<Value, Error, State<Value, Error>>
13+
channel: Channel<Value, Error>
1414
)]
1515

1616
/// DataLoader creates a public API for loading data from a particular
@@ -25,7 +25,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
2525
private let batchLoadFunction: BatchLoadFunction<Key, Value>
2626
private let options: DataLoaderOptions<Key, Value>
2727

28-
private var cache = [Key: Channel<Value, Error, State<Value, Error>>]()
28+
private var cache = [Key: Channel<Value, Error>]()
2929
private var queue = LoaderQueue<Key, Value>()
3030

3131
private var dispatchScheduled = false
@@ -46,7 +46,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
4646
return try await cached.value
4747
}
4848

49-
let channel = Channel<Value, Error, State<Value, Error>>()
49+
let channel = Channel<Value, Error>()
5050

5151
if options.batchingEnabled {
5252
queue.append((key: key, channel: channel))
@@ -148,7 +148,7 @@ public actor DataLoader<Key: Hashable & Sendable, Value: Sendable> {
148148
let cacheKey = options.cacheKeyFunction?(key) ?? key
149149

150150
if cache[cacheKey] == nil {
151-
let channel = Channel<Value, Error, State<Value, Error>>()
151+
let channel = Channel<Value, Error>()
152152

153153
Task.detached {
154154
await channel.fulfill(value)

0 commit comments

Comments
 (0)