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

io.github.sinri.keel.facade.async.FutureSleep Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

The newest version!
package io.github.sinri.keel.facade.async;

import io.vertx.core.Future;
import io.vertx.core.Promise;

import javax.annotation.Nullable;

import static io.github.sinri.keel.facade.KeelInstance.Keel;

/**
 * 将延时执行转换成Future供compose使用。
 * Promise 真是个好东西!
 *
 * @since 2.9
 */
public class FutureSleep {
    static Future call(long time) {
        return call(time, null);
    }

    static Future call(long time, @Nullable Promise interrupter) {
        Promise promise = Promise.promise();
        if (time < 1) time = 1;
        long timer_id = Keel.getVertx().setTimer(time, timerID -> {
            promise.complete();
        });
        if (interrupter != null) {
            interrupter.future().onSuccess(interrupted -> {
                Keel.getVertx().cancelTimer(timer_id);
                promise.tryComplete();
            });
        }
        return promise.future();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy