All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.p8e.util.CompletableFutureUtil.kt Maven / Gradle / Ivy

Go to download

A collection of services and libraries that iteract and run Provenance Java based contracts.

The newest version!
package io.p8e.util

import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import kotlin.concurrent.thread

object CompletableFutureUtil {
    fun  completableFuture(executor: ExecutorService, fn: () -> T): CompletableFuture {
        val completableFuture = CompletableFuture()
        thread(start = false) {
            try {
                completableFuture.complete(fn())
            } catch(t: Throwable) {
                completableFuture.completeExceptionally(t)
            }
        }.let(executor::submit)
        return completableFuture
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy