Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add suspend functions for Vertx coroutine usage #51

Closed
feiyanke opened this issue Mar 8, 2018 · 2 comments
Closed

add suspend functions for Vertx coroutine usage #51

feiyanke opened this issue Mar 8, 2018 · 2 comments

Comments

@feiyanke
Copy link

feiyanke commented Mar 8, 2018

I think that is useful for coroutine usage like some functions below:

suspend fun Vertx.adelay(ms:Long) = awaitEvent<Long> { setTimer(ms, it) }
suspend fun Vertx.adeploy(verticle: Verticle, option:DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticle, option, it)
}
suspend fun Vertx.adeploy(verticle:String, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticle, option, it)
}
suspend fun Vertx.adeploy(verticleSupplier:Supplier<Verticle>, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticleSupplier, option, it)
}
suspend fun <T:Verticle> Vertx.adeploy(verticleClass: Class<T>, option: DeploymentOptions = DeploymentOptions()) = awaitResult<String> {
    deployVerticle(verticleClass, option, it)
}
suspend fun Vertx.aundeploy(deployId:String) = awaitResult<Void> {
    undeploy(deployId, it)
}
suspend fun <T> Vertx.arunBlocking(order:Boolean = true, block:()->T) = awaitResult<T> {
    executeBlocking(Handler<Future<T>> { f ->
        try {
            f.complete(block())
        } catch (e:Throwable) {
            f.fail(e)
        }
    }, order, it)
}

if needed, I can make a PR for these kind of extensions

@vietj
Copy link
Contributor

vietj commented Mar 8, 2018

I've created this issue a while ago that proposes to do that in a generic manner using the Vert.x code generator : #41 . I would prefer a contribution on this issue instead.

@feiyanke
Copy link
Author

feiyanke commented Mar 9, 2018

all right, that's cool.

@vietj vietj closed this as completed Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants