Deactivated User
12/22/2016, 12:11 PMinterface AsyncDependency {
fun initAsync(): Promise<Unit>
}
That is now:
interface AsyncDependency {
suspend fun init(): Unit
}
@Singleton
class Missions(
val project: ProjectConfig,
val s3client: AmazonS3Client,
val buckets: BucketsConfig,
val redis: RedisClient
) : AsyncDependency {
lateinit var missionsBytes: ByteArray
suspend override fun init() = await(async {
missionsBytes = await(readResourceAsync("Missions.json"))
}
}
It would be awesome to be able to suspend the constructor itself somehow to avoid lateinit var + other stuff:
@Singleton
class Missions suspend(
val project: ProjectConfig,
val s3client: AmazonS3Client,
val buckets: BucketsConfig,
val redis: RedisClient
) {
val missionsBytes = readResource("Missions.json")
}
But probably it is too complex, right? But that would be totally a dream. Anyway I'm so hyped right now 🙂
I can see constructors like function calls, so something like this could be implemented internally creating a suspend function, and calling it at construction. The construction would be allowed just inside suspending blocks.