@@ -3,14 +3,28 @@ package dev.helight.krescent.event.processor
33import dev.helight.krescent.HandlerChainParticipant
44import dev.helight.krescent.event.Event
55import dev.helight.krescent.event.EventStreamProcessor
6+ import dev.helight.krescent.event.SystemEvent
67import java.util.function.Consumer
78
89class BroadcastEventStreamProcessor (
910 private val processors : List <EventStreamProcessor >,
1011) : EventStreamProcessor {
12+
1113 override suspend fun process (event : Event ) {
12- for (processor in processors) {
13- processor.process(event)
14+ if (event is SystemEvent ) {
15+ val exceptions = mutableListOf<Exception >()
16+ for (processor in processors) {
17+ try {
18+ processor.process(event)
19+ } catch (ex: Exception ) {
20+ exceptions.add(ex)
21+ }
22+ }
23+ if (exceptions.isNotEmpty()) throw SystemEventException (exceptions)
24+ } else {
25+ for (processor in processors) {
26+ processor.process(event)
27+ }
1428 }
1529 }
1630
@@ -20,4 +34,8 @@ class BroadcastEventStreamProcessor(
2034 processor.accept(visitor)
2135 }
2236 }
37+
38+ class SystemEventException (
39+ val exceptions : List <Exception >,
40+ ) : Exception(" Exceptions have occurred while processing a system event: ${exceptions.map { it.message }} " )
2341}
0 commit comments