Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Oct 28, 2023
1 parent b7d6b5f commit d1d3623
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
54 changes: 35 additions & 19 deletions Sources/Verge/Store/AnyTargetQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ extension TargetQueueType where Self == Queues.Passthrough {

}

extension TargetQueueType where Self == Queues.AsyncBackground {
/// It dispatches to the serial background queue asynchronously.
public static var asyncSerialBackground: Self {
self.init()
}
}

extension TargetQueueType where Self == AnyTargetQueue {


Expand All @@ -123,10 +130,7 @@ extension TargetQueueType where Self == AnyTargetQueue {
targetQueue.async(execute: workItem)
}
}
/// It dispatches to the serial background queue asynchronously.
public static var asyncSerialBackground: AnyTargetQueue {
AnyTargetQueue._asyncSerialBackground
}


/// Enqueue first item on current-thread(synchronously).
/// From then, using specified queue.
Expand Down Expand Up @@ -175,21 +179,6 @@ extension MainActorTargetQueue {
}
}

extension AnyTargetQueue {

/// Returns a instance that never dispatches.
/// The Sink use this targetQueue performs in the queue which the upstream commit dispatched.
static let _passthrough: AnyTargetQueue = .init { workItem in
workItem()
}

/// It dispatches to the serial background queue asynchronously.
static let _asyncSerialBackground: AnyTargetQueue = .init { workItem in
StaticMember.serialBackgroundDispatchQueue.async(execute: workItem)
}

}

public enum Queues {

struct MainActor: TargetQueueType {
Expand All @@ -214,4 +203,31 @@ public enum Queues {

}

public struct AsyncBackground: TargetQueueType {

private let executor: BackgroundActor = .init()

public func execute(_ workItem: @escaping () -> Void) {
Task {
await executor.perform {
workItem()
}
}
}

private actor BackgroundActor: Actor {

init() {

}

func perform<R>(_ operation: () throws -> R) rethrows -> R {
try operation()
}

}

}

}

7 changes: 6 additions & 1 deletion Sources/Verge/Utility/ReferenceEdge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ public struct ReferenceEdge<State>: EdgeType {
}

public var projectedValue: Self {
self
get {
self
}
mutating set {
self = newValue
}
}

public func read<T>(_ thunk: (borrowing State) -> T) -> T {
Expand Down

0 comments on commit d1d3623

Please sign in to comment.