1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.util.concurrency; 18 19 import java.util.concurrent.Executor; 20 import java.util.concurrent.TimeUnit; 21 22 /** 23 * A sub-class of {@link Executor} that allows Runnables to be delayed and/or cancelled. 24 */ 25 public interface DelayableExecutor extends Executor { 26 /** 27 * Execute supplied Runnable on the Executors thread after a specified delay. 28 * 29 * See {@link android.os.Handler#postDelayed(Runnable, long)}. 30 * 31 * @return A Runnable that, when run, removes the supplied argument from the Executor queue. 32 */ executeDelayed(Runnable r, long delayMillis)33 default Runnable executeDelayed(Runnable r, long delayMillis) { 34 return executeDelayed(r, delayMillis, TimeUnit.MILLISECONDS); 35 } 36 37 /** 38 * Execute supplied Runnable on the Executors thread after a specified delay. 39 * 40 * See {@link android.os.Handler#postDelayed(Runnable, long)}. 41 * 42 * @return A Runnable that, when run, removes the supplied argument from the Executor queue.. 43 */ executeDelayed(Runnable r, long delay, TimeUnit unit)44 Runnable executeDelayed(Runnable r, long delay, TimeUnit unit); 45 46 /** 47 * Execute supplied Runnable on the Executors thread at a specified uptime. 48 * 49 * See {@link android.os.Handler#postAtTime(Runnable, long)}. 50 * 51 * @return A Runnable that, when run, removes the supplied argument from the Executor queue. 52 */ executeAtTime(Runnable r, long uptime)53 default Runnable executeAtTime(Runnable r, long uptime) { 54 return executeAtTime(r, uptime, TimeUnit.MILLISECONDS); 55 } 56 57 /** 58 * Execute supplied Runnable on the Executors thread at a specified uptime. 59 * 60 * See {@link android.os.Handler#postAtTime(Runnable, long)}. 61 * 62 * @return A Runnable that, when run, removes the supplied argument from the Executor queue. 63 */ executeAtTime(Runnable r, long uptimeMillis, TimeUnit unit)64 Runnable executeAtTime(Runnable r, long uptimeMillis, TimeUnit unit); 65 } 66