Skip to content

Commit

Permalink
[ark-event] fix: copy events each tick to process events available pe…
Browse files Browse the repository at this point in the history
…r tick
  • Loading branch information
didymental committed Apr 14, 2024
1 parent 5a6417a commit 8699843
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ArkKit/ark-event-kit/ArkEventManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ class ArkEventManager: ArkEventContext {
}

func processEvents() {
while !eventQueue.isEmpty {
guard let datedEvent = eventQueue.dequeue() else {
// copy eventQueue so that events emited during processing are processed at the next tick
var eventsFromQueue = eventQueue
while !eventsFromQueue.isEmpty {
guard let datedEvent = eventsFromQueue.dequeue() else {
fatalError("[ArkEventManager.processEvents()] dequeue failed: Expected event, found nil.")
}
// dequeue from copy and actual eventQueue so that they are in sync
_ = eventQueue.dequeue()
guard let listenersToExecute = listeners[ObjectIdentifier(type(of: datedEvent.event))] else {
continue
}
Expand Down

0 comments on commit 8699843

Please sign in to comment.