blob: 7000c2d2224a00a8c6fec8ea70aff90207cc4b94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import me.bush.illnamethislater.*
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.config.Configurator
/**
* @author bush
* @since 1.0.0
*/
fun main() {
Configurator.setRootLevel(Level.INFO)
EventBus().run {
subscribe(Subscriber())
post(External())
// val key = register(listener<Int> {
// println(it)
// })
//
// val topLevelListenerKey = register(topLevelListener())
//
// unsubscribe(key)
//
// unsubscribe(topLevelListenerKey)
//
// debugInfo()
}
}
fun topLevelListener() = listener<Int> {
println("topLevelListener(): $it")
}
class Subscriber {
val listener0 = listener<External>(500) {
println("listener 0")
println(it.canceled)
it.canceled = true
}
val listener1 = listener<External>(250, receiveCancelled = true) {
println("listener 1")
println(it.canceled)
it.canceled = false
}
val listener2 get() = listener<External> {
println("listener 2")
println(it.canceled)
it.canceled = true
}
fun listener3() = listener<External>(-250) {
println("listener 3")
println(it.canceled)
}
}
class External {
var canceled = false
}
|