TaskSingleDrainerpublic class TaskSingleDrainer extends Object Keep track of a single concurrent task starting and finishing;
allow draining the existing task and figuring out when the task has finished
(and won't restart).
The initial state is to allow all tasks to be started and finished. A task may only be started
once, after which it must be finished before starting again. Likewise, finishing a task
that hasn't been started is also not allowed.
When draining begins, the task cannot be started again. This guarantees that at some
point the task will be finished forever, at which point the {@link DrainListener#onDrained}
callback will be invoked. |
Fields Summary |
---|
private final TaskDrainer | mTaskDrainer | private final Object | mSingleTask |
Methods Summary |
---|
public void | beginDrain()Do not allow any more task re-starts; once the existing task is finished,
fire the {@link DrainListener#onDrained} callback asynchronously.
This operation is idempotent; calling it more than once has no effect.
mTaskDrainer.beginDrain();
| public void | taskFinished()Mark this asynchronous task as having finished.
The task cannot be finished if it hasn't started. Once finished, a task
cannot be finished again (unless it's started again).
mTaskDrainer.taskFinished(mSingleTask);
| public void | taskStarted()Mark this asynchronous task as having started.
The task cannot be started more than once without first having finished. Once
draining begins with {@link #beginDrain}, no new tasks can be started.
mTaskDrainer.taskStarted(mSingleTask);
|
|