Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Mar 17, 2024
1 parent 35772f6 commit 92b8c98
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Sources/Verge/Library/EventEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ protocol EventEmitterType: AnyObject {
func removeEventHandler(_ token: EventEmitterCancellable)
}

public protocol EventEmitterEventType {
func onComsume()
}

/// Instead of Combine
open class EventEmitter<Event>: EventEmitterType, @unchecked Sendable {
open class EventEmitter<Event: EventEmitterEventType>: EventEmitterType, @unchecked Sendable {

public var publisher: Publisher {
return .init(eventEmitter: self)
Expand Down Expand Up @@ -107,6 +111,7 @@ open class EventEmitter<Event>: EventEmitterType, @unchecked Sendable {

for subscriber in capturedSubscribers {
subscriber.1(event)
event.onComsume()
}
}

Expand Down
31 changes: 29 additions & 2 deletions Sources/Verge/Store/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,27 @@ public typealias NoActivityStoreBase<State: Equatable> = Store<State, Never>

private let sanitizerQueue = DispatchQueue.init(label: "org.vergegroup.verge.sanitizer")

public enum _StoreEvent<State: Equatable, Activity> {
public enum _StoreEvent<State: Equatable, Activity>: EventEmitterEventType {

public enum StateEvent {
case willUpdate
case didUpdate(Changes<State>)
}

case state(StateEvent)
case activity(Activity)
case waiter(() -> Void)

public func onComsume() {
switch self {
case .state:
break
case .activity:
break
case .waiter(let closure):
closure()
}
}
}

actor Writer {
Expand Down Expand Up @@ -219,6 +231,8 @@ open class Store<State: Equatable, Activity>: EventEmitter<_StoreEvent<State, Ac
}
case .activity:
break
case .waiter:
break
}
}

Expand Down Expand Up @@ -306,6 +320,19 @@ extension Store {

}

// MARK: - Wait
extension Store {

public func waitUntilFinishedAllEvents() async {
await withUnsafeContinuation { c in
accept(.waiter({
c.resume()
}))
}
}

}

// MARK: - Middleware
extension Store {

Expand Down

0 comments on commit 92b8c98

Please sign in to comment.