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  * @author Doug Lea
28  */
29 interface Delayed : Comparable!(Delayed) {
30 
31     /**
32      * Returns the remaining delay associated with this object, in the
33      * given time unit.
34      *
35      * @param unit the time unit
36      * @return the remaining delay; zero or negative values indicate
37      * that the delay has already elapsed
38      */
39     Duration getDelay();
40 }
41 
42 
43 
44 /**
45  * A delayed result-bearing action that can be cancelled.
46  * Usually a scheduled future is the result of scheduling
47  * a task with a {@link ScheduledExecutorService}.
48  *
49  * @author Doug Lea
50  * @param (V) The result type returned by this Future
51  */
52 interface ScheduledFuture(V) : Delayed, Future!(V) {
53 }
54 
55 
56 /**
57  * A {@link ScheduledFuture} that is {@link Runnable}. Successful
58  * execution of the {@code run} method causes completion of the
59  * {@code Future} and allows access to its results.
60  * @see FutureTask
61  * @see Executor
62  * @author Doug Lea
63  * @param (V) The result type returned by this Future's {@code get} method
64  */
65 interface RunnableScheduledFuture(V) : RunnableFuture!(V), 
66     ScheduledFuture!(V), IRunnableScheduledFuture {
67 
68     /**
69      * Returns {@code true} if this task is periodic. A periodic task may
70      * re-run according to some schedule. A non-periodic task can be
71      * run only once.
72      *
73      * @return {@code true} if this task is periodic
74      */
75     bool isPeriodic();
76 }
77 
78 interface IRunnableScheduledFuture : Delayed, Runnable {
79     
80     bool isPeriodic();
81 
82     bool cancel(bool mayInterruptIfRunning);
83 
84     bool isCancelled();
85 }