1 /*
2  * Hunt - A refined core library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.concurrency.Delayed;
13 
14 import hunt.concurrency.Future;
15 
16 import hunt.util.Common;
17 import core.time;
18 
19 /**
20  * A mix-in style interface for marking objects that should be
21  * acted upon after a given delay.
22  *
23  * <p>An implementation of this interface must define a
24  * {@code compareTo} method that provides an ordering consistent with
25  * its {@code getDelay} method.
26  *
27  * @since 1.5
28  * @author Doug Lea
29  */
30 interface Delayed : Comparable!(Delayed) {
31 
32     /**
33      * Returns the remaining delay associated with this object, in the
34      * given time unit.
35      *
36      * @param unit the time unit
37      * @return the remaining delay; zero or negative values indicate
38      * that the delay has already elapsed
39      */
40     Duration getDelay();
41 }
42 
43 
44 
45 /**
46  * A delayed result-bearing action that can be cancelled.
47  * Usually a scheduled future is the result of scheduling
48  * a task with a {@link ScheduledExecutorService}.
49  *
50  * @since 1.5
51  * @author Doug Lea
52  * @param (V) The result type returned by this Future
53  */
54 interface ScheduledFuture(V) : Delayed, Future!(V) {
55 }
56 
57 
58 /**
59  * A {@link ScheduledFuture} that is {@link Runnable}. Successful
60  * execution of the {@code run} method causes completion of the
61  * {@code Future} and allows access to its results.
62  * @see FutureTask
63  * @see Executor
64  * @since 1.6
65  * @author Doug Lea
66  * @param (V) The result type returned by this Future's {@code get} method
67  */
68 interface RunnableScheduledFuture(V) : RunnableFuture!(V), ScheduledFuture!(V), IRunnableScheduledFuture{
69 
70     /**
71      * Returns {@code true} if this task is periodic. A periodic task may
72      * re-run according to some schedule. A non-periodic task can be
73      * run only once.
74      *
75      * @return {@code true} if this task is periodic
76      */
77     bool isPeriodic();
78 }
79 
80 interface IRunnableScheduledFuture : Delayed, Runnable {
81     bool isPeriodic();
82     bool cancel(bool mayInterruptIfRunning);
83     bool isCancelled();
84 }