File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
common/src/main/kotlin/com/lambda/event Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 11package com.lambda.event
22
3+ /* *
4+ * Represents an event that supports providing feedback after being posted to the [EventFlow].
5+ *
6+ * A [CallbackEvent] can be modified and listened to only from synchronous listeners ([EventFlow.syncListeners]).
7+ * This allows the event to provide feedback after its invocation.
8+ *
9+ * Implement this interface when you need an event to return data back to the caller after being processed by the listeners.
10+ *
11+ * Usage:
12+ * ```kotlin
13+ * class MyCallbackEvent : CallbackEvent {
14+ * var result: ResultType? = null
15+ * }
16+ *
17+ * object MyListener {
18+ * init {
19+ * // will be executed on the game thread synchronously
20+ * listener<MyCallbackEvent> { event ->
21+ * // will be readable after the event is posted
22+ * event.result = processEvent(event)
23+ * // ...
24+ * }
25+ *
26+ * // will be executed on a dedicated thread asynchronously
27+ * concurrentListener<MyCallbackEvent> { event ->
28+ * // will not be readable after the event is posted as it takes time to execute
29+ * event.result = processEvent(event)
30+ * }
31+ * }
32+ * }
33+ *
34+ * val event = MyCallbackEvent()
35+ * EventFlow.post(event)
36+ * val result = event.result
37+ * ```
38+ */
339interface CallbackEvent : Event
Original file line number Diff line number Diff line change 11package com.lambda.event
22
3+ /* *
4+ * The base interface for all [Event]s in the system.
5+ *
6+ * An [Event] represents a state or condition that can be listened for and acted upon.
7+ * It serves as a communication mechanism between different parts of an application.
8+ *
9+ * Subclasses of [Event] should encapsulate relevant information about the event's context and state.
10+ *
11+ * Implementations of this interface can be posted to the [EventFlow] for processing by registered listeners.
12+ *
13+ * Usage:
14+ * ```kotlin
15+ * class MyEvent(val message: String) : Event
16+ *
17+ * object MyListener {
18+ * init {
19+ * listener<MyEvent> { event -> println(event.message) }
20+ * }
21+ * }
22+ *
23+ * EventFlow.post(MyEvent("Hello, world!"))
24+ * ```
25+ */
326interface Event
Original file line number Diff line number Diff line change @@ -38,3 +38,5 @@ abstract class PacketEvent : Event {
3838 abstract class Receive : PacketEvent () {
3939 class Pre (val packet : Packet <* >) : Receive(), ICancellable by Cancellable()
4040 class Post (val packet : Packet <* >) : Receive()
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments