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 hunt.util.Runnable;
18 import core.time;
19 
20 /**
21  * A mix-in style interface for marking objects that should be
22  * acted upon after a given delay.
23  *
24  * <p>An implementation of this interface must define a
25  * {@code compareTo} method that provides an ordering consistent with
26  * its {@code getDelay} method.
27  *
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  * @author Doug Lea
51  * @param (V) The result type returned by this Future
52  */
53 interface ScheduledFuture(V) : Delayed, Future!(V) {
54 }
55 
56 
57 /**
58  * A {@link ScheduledFuture} that is {@link Runnable}. Successful
59  * execution of the {@code run} method causes completion of the
60  * {@code Future} and allows access to its results.
61  * @see FutureTask
62  * @see Executor
63  * @author Doug Lea
64  * @param (V) The result type returned by this Future's {@code get} method
65  */
66 interface RunnableScheduledFuture(V) : RunnableFuture!(V), 
67     ScheduledFuture!(V), IRunnableScheduledFuture {
68 
69     /**
70      * Returns {@code true} if this task is periodic. A periodic task may
71      * re-run according to some schedule. A non-periodic task can be
72      * run only once.
73      *
74      * @return {@code true} if this task is periodic
75      */
76     bool isPeriodic();
77 }
78 
79 interface IRunnableScheduledFuture : Delayed, Runnable {
80     
81     bool isPeriodic();
82 
83     bool cancel(bool mayInterruptIfRunning);
84 
85     bool isCancelled();
86 }