Skip to content

Commit 426bc9b

Browse files
committed
EventListener improvement for .requesterThread
- `EventListener` will now raise a `Task` to invoke the callback on the `.requesterThread`. This prevents the entire `EventListener` from being blocked in the event that the `.requesterThread` is blocked.
1 parent 701eb3e commit 426bc9b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/EventDrivenSwift/EventListener/EventListener.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ open class EventListener: EventHandler, EventListenable {
5555
listeners = eventListeners[eventTypeName]
5656
}
5757

58-
if listeners == nil { return } // If there is no Callback, we will just return!
58+
if listeners == nil { return } // If there are no Listeners, we will just return!
5959

6060
for listener in listeners! {
6161
if listener.requester == nil { // If the Requester no longer exists...
@@ -64,9 +64,11 @@ open class EventListener: EventHandler, EventListenable {
6464
}
6565
switch listener.executeOn {
6666
case .requesterThread:
67-
let dispatchQueue = listener.dispatchQueue ?? DispatchQueue.main
68-
dispatchQueue.async {
69-
listener.callback(event, priority)
67+
Task { // We raise a Task because we don't want the entire Listener blocked in the event the dispatchQueue is busy or blocked!
68+
let dispatchQueue = listener.dispatchQueue ?? DispatchQueue.main
69+
dispatchQueue.async {
70+
listener.callback(event, priority)
71+
}
7072
}
7173
case .listenerThread:
7274
listener.callback(event, priority)

0 commit comments

Comments
 (0)