// Path: core/src/main/java/com/github/phantomthief/concurrent/MoreFutures.java
// public static Future<?> scheduleWithDynamicDelay(@Nonnull ScheduledExecutorService executor,
//         @Nullable Duration initDelay, @Nonnull Scheduled task) {
//     checkNotNull(executor);
//     checkNotNull(task);
//     AtomicBoolean canceled = new AtomicBoolean(false);
//     AbstractFuture<?> future = new AbstractFuture<Object>() {
// 
//         @Override
//         public boolean cancel(boolean mayInterruptIfRunning) {
//             canceled.set(true);
//             return super.cancel(mayInterruptIfRunning);
//         }
//     };
//     executor.schedule(new ScheduledTaskImpl(executor, task, canceled),
//             initDelay == null ? 0 : initDelay.toMillis(), MILLISECONDS);
//     return future;
// }


import static com.github.phantomthief.concurrent.MoreFutures.scheduleWithDynamicDelay;
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.time.Duration.ofSeconds;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.github.phantomthief.concurrent;




/**
 * @author w.vela
 * Created on 2019-11-26.
 */
class MoreFuturesDynamicTest {

    private static final Logger logger = LoggerFactory.getLogger(MoreFuturesDynamicTest.class);

    @Test
    void test() {
        ScheduledExecutorService scheduled = newSingleThreadScheduledExecutor();
        int[] i = {1};
        int[] run = {0};
// Path: core/src/main/java/com/github/phantomthief/concurrent/MoreFutures.java
// public static Future<?> scheduleWithDynamicDelay(@Nonnull ScheduledExecutorService executor,
//         @Nullable Duration initDelay, @Nonnull Scheduled task) {
//     checkNotNull(executor);
//     checkNotNull(task);
//     AtomicBoolean canceled = new AtomicBoolean(false);
//     AbstractFuture<?> future = new AbstractFuture<Object>() {
// 
//         @Override
//         public boolean cancel(boolean mayInterruptIfRunning) {
//             canceled.set(true);
//             return super.cancel(mayInterruptIfRunning);
//         }
//     };
//     executor.schedule(new ScheduledTaskImpl(executor, task, canceled),
//             initDelay == null ? 0 : initDelay.toMillis(), MILLISECONDS);
//     return future;
// }


// Path: core/src/test/java/com/github/phantomthief/concurrent/MoreFuturesDynamicTest.java
import static com.github.phantomthief.concurrent.MoreFutures.scheduleWithDynamicDelay;
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.time.Duration.ofSeconds;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package com.github.phantomthief.concurrent;




/**
 * @author w.vela
 * Created on 2019-11-26.
 */
class MoreFuturesDynamicTest {

    private static final Logger logger = LoggerFactory.getLogger(MoreFuturesDynamicTest.class);

    @Test
    void test() {
        ScheduledExecutorService scheduled = newSingleThreadScheduledExecutor();
        int[] i = {1};
        int[] run = {0};
        Future<?> future = scheduleWithDynamicDelay(scheduled, () -> {