<commit_before>package uy.klutter.vertx

import io.vertx.core.*
import nl.komponents.kovenant.Deferred
import nl.komponents.kovenant.Kovenant
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.deferred
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.ZonedDateTime
import java.time.temporal.Temporal
import kotlin.reflect.KClass
import kotlin.reflect.jvm.java


/**
 *  VertxInit.ensure() is called from methods that startup vertx to be sure Kovenant and Vertx are configured to work
 *  together.  If you do not startup vertx using these methods, you should directly call VertxInit.ensure() at the start
 *  of your application.  Not all vertx+Kovenant methods call VertxInit.ensure, although those that will not affect performance
 *  might.
 */

public class WrappedThrowableException(cause: Throwable): Exception(cause.getMessage(), cause)

/**
 * Start vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertx(): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    try {
        deferred.resolve(Vertx.vertx())
    } catch (ex: Exception) {
        deferred.reject(ex)
    } catch (ex: Throwable) {
        deferred.reject(WrappedThrowableException(ex))
    }
    return deferred.promise
}

/**
 * Start vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertx(options: VertxOptions): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    try {
        deferred.resolve(Vertx.vertx(options))
    } catch (ex: Exception) {
        deferred.reject(ex)
    }  catch (ex: Throwable) {
        deferred.reject(WrappedThrowableException(ex))
    }
    return deferred.promise
}

/**
 * Start clustered vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertxCluster(options: VertxOptions): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    Vertx.clusteredVertx(options, promiseResult(deferred))
    return deferred.promise
}

/**
 * retrieve the current vert.x context if one is attached to the current thread
 */
public fun vertxContext(): Context? = Vertx.currentContext()

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(verticle: Verticle): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticle, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(verticle: Verticle, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticle, options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: KClass<T>): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.java.getName(), promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: KClass<T>, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.java.getName(), options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: Class<T>): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.getName(), promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: Class<T>, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.getName(), options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(name: String): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(name, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(name: String, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(name, options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle async without waiting for it to complete
 */
public fun <T : AbstractVerticle> Vertx.deployVerticle(verticleClass: KClass<T>): Unit {
    deployVerticle(verticleClass.java.getName())
}

/**
 * Deploy a verticle async without waiting for it to complete
 */
public fun <T : AbstractVerticle> Vertx.deployVerticle(verticleClass: Class<T>): Unit {
    deployVerticle(verticleClass.getName())
}


public class NADA {} // we can't deal with Void return type Vert.x likes to define but really means NULL but isn't nullable
val nada = NADA()

/**
 * Undeploy a verticle, returning a Promise<NADA, Exception>
 */
public fun Vertx.promiseUndeploy(deploymentId: String): Promise<NADA, Exception> {
    VertxInit.ensure()

    val deferred = deferred<NADA, Exception>()
    this.undeploy(deploymentId, { completion ->
        if (completion.succeeded()) {
            deferred.resolve(nada)
        } else {
            if (completion.cause() is Exception) {
                deferred.reject(completion.cause() as Exception)
            } else {
                deferred.reject(WrappedThrowableException(completion.cause()))
            }
        }
    })
    return deferred.promise
}
<commit_msg>Fix Void return from async things in vert.x that break promises release 0.3.3<commit_after>package uy.klutter.vertx

import io.vertx.core.*
import nl.komponents.kovenant.Deferred
import nl.komponents.kovenant.Kovenant
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.deferred
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.time.ZonedDateTime
import java.time.temporal.Temporal
import kotlin.reflect.KClass
import kotlin.reflect.jvm.java


/**
 *  VertxInit.ensure() is called from methods that startup vertx to be sure Kovenant and Vertx are configured to work
 *  together.  If you do not startup vertx using these methods, you should directly call VertxInit.ensure() at the start
 *  of your application.  Not all vertx+Kovenant methods call VertxInit.ensure, although those that will not affect performance
 *  might.
 */

public class WrappedThrowableException(cause: Throwable): Exception(cause.getMessage(), cause)

/**
 * Start vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertx(): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    try {
        deferred.resolve(Vertx.vertx())
    } catch (ex: Exception) {
        deferred.reject(ex)
    } catch (ex: Throwable) {
        deferred.reject(WrappedThrowableException(ex))
    }
    return deferred.promise
}

/**
 * Start vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertx(options: VertxOptions): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    try {
        deferred.resolve(Vertx.vertx(options))
    } catch (ex: Exception) {
        deferred.reject(ex)
    }  catch (ex: Throwable) {
        deferred.reject(WrappedThrowableException(ex))
    }
    return deferred.promise
}

/**
 * Start clustered vert.x returning a Kovenant Promise<Vertx, Exception>
 */
public fun vertxCluster(options: VertxOptions): Promise<Vertx, Exception> {
    VertxInit.ensure()

    val deferred = deferred<Vertx, Exception>()
    Vertx.clusteredVertx(options, promiseResult(deferred))
    return deferred.promise
}

/**
 * retrieve the current vert.x context if one is attached to the current thread
 */
public fun vertxContext(): Context? = Vertx.currentContext()

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(verticle: Verticle): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticle, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(verticle: Verticle, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticle, options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: KClass<T>): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.java.getName(), promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: KClass<T>, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.java.getName(), options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: Class<T>): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.getName(), promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun  <T : AbstractVerticle> Vertx.promiseDeployVerticle(verticleClass: Class<T>, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(verticleClass.getName(), options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(name: String): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(name, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle, returning a Promise<deploymentId as String, Exception>
 */
public fun Vertx.promiseDeployVerticle(name: String, options: DeploymentOptions): Promise<String, Exception> {
    VertxInit.ensure()

    val deferred = deferred<String, Exception>()
    deployVerticle(name, options, promiseResult(deferred))
    return deferred.promise
}

/**
 * Deploy a verticle async without waiting for it to complete
 */
public fun <T : AbstractVerticle> Vertx.deployVerticle(verticleClass: KClass<T>): Unit {
    deployVerticle(verticleClass.java.getName())
}

/**
 * Deploy a verticle async without waiting for it to complete
 */
public fun <T : AbstractVerticle> Vertx.deployVerticle(verticleClass: Class<T>): Unit {
    deployVerticle(verticleClass.getName())
}

public class NADA {} // we can't deal with Void return type Vert.x likes to define but really means NULL but isn't nullable
val nada = NADA()

/**
 * Undeploy a verticle, returning a Promise<NADA, Exception>
 */
public fun Vertx.promiseUndeploy(deploymentId: String): Promise<NADA, Exception> {
    VertxInit.ensure()

    val deferred = deferred<NADA, Exception>()
    this.undeploy(deploymentId, { completion ->
        if (completion.succeeded()) {
            deferred.resolve(nada)
        } else {
            if (completion.cause() is Exception) {
                deferred.reject(completion.cause() as Exception)
            } else {
                deferred.reject(WrappedThrowableException(completion.cause()))
            }
        }
    })
    return deferred.promise
}

{'fraction_non_alphanumeric': 0.10602652602187233, 'fraction_numerical': 0.00023268440238889319, 'mean_word_length': 4.2822613682916835, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '368500', 'n_tokens_mistral': 3854, 'n_tokens_neox': 3708, 'n_words': 992}