aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/subscription/SubscriptionList.kt
blob: e74a65a8b21bc25f14caf7eb1c269c1a0e7d69b1 (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
package moe.nea.firmament.events.subscription

import java.util.ServiceLoader
import kotlin.streams.asSequence
import moe.nea.firmament.Firmament

interface SubscriptionList {
    fun provideSubscriptions(addSubscription: (Subscription<*>) -> Unit)

    companion object {
        val allLists by lazy {
            ServiceLoader.load(SubscriptionList::class.java)
                .stream()
                .asSequence()
                .mapNotNull {
                    kotlin.runCatching { it.get() }
                        .getOrElse { ex ->
                            Firmament.logger.error("Could not load subscriptions from ${it.type()}", ex)
                            null
                        }
                }
                .toList()
        }
    }
}