Add top-level fun for subscribeAll

This commit is contained in:
Him188 2019-10-11 07:48:30 +08:00 committed by GitHub
parent a9b3ecf5ea
commit 8e323644ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,6 +60,15 @@ fun <E : Event> KClass<E>.subscribeAll(listeners: ListenerBuilder<E>.() -> Unit)
ListenerBuilder<E> { this.subscribeInternal(it) }.apply(listeners)
}
/**
* 监听一个事件. 可同时进行多种方式的监听
* @see ListenerBuilder
*/
inline fun <reified E : Event> subscribeAll(noinline listeners: ListenerBuilder<E>.() -> Unit) {
ListenerBuilder<E> { this.subscribeInternal(it) }.apply(listeners)
}
/**
* 监听构建器. 可同时进行多种方式的监听
*
@ -99,4 +108,4 @@ inline class ListenerBuilder<out E : Event>(
fun once(block: suspend (E) -> Unit) = handler { block(it); ListeningStatus.STOPPED }
}
}