2019-01-15 00:41:05 -08:00
|
|
|
package org.thoughtcrime.securesms.net;
|
|
|
|
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
2019-01-15 00:41:05 -08:00
|
|
|
|
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class CompositeRequestController implements RequestController {
|
|
|
|
|
|
|
|
private final List<RequestController> controllers = new ArrayList<>();
|
|
|
|
private boolean canceled = false;
|
|
|
|
|
|
|
|
public synchronized void addController(@NonNull RequestController controller) {
|
|
|
|
if (canceled) {
|
|
|
|
controller.cancel();
|
|
|
|
} else {
|
|
|
|
controllers.add(controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void cancel() {
|
|
|
|
canceled = true;
|
|
|
|
Stream.of(controllers).forEach(RequestController::cancel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized boolean isCanceled() {
|
|
|
|
return canceled;
|
|
|
|
}
|
|
|
|
}
|