| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.schedulers; |
| 15 |
|
| 16 |
import io.reactivex.rxjava3.annotations.NonNull; |
| 17 |
import io.reactivex.rxjava3.core.Scheduler; |
| 18 |
|
| 19 |
/** |
| 20 |
* Allows retrieving multiple workers from the implementing |
| 21 |
* {@link io.reactivex.rxjava3.core.Scheduler} in a way that when asking for |
| 22 |
* at most the parallelism level of the Scheduler, those |
| 23 |
* {@link io.reactivex.rxjava3.core.Scheduler.Worker} instances will be running |
| 24 |
* with different backing threads. |
| 25 |
* <p>History: 2.1.8 - experimental |
| 26 |
* @since 2.2 |
| 27 |
*/ |
| 28 |
public interface SchedulerMultiWorkerSupport { |
| 29 |
|
| 30 |
/** |
| 31 |
* Creates the given number of {@link io.reactivex.rxjava3.core.Scheduler.Worker} instances |
| 32 |
* that are possibly backed by distinct threads |
| 33 |
* and calls the specified {@code Consumer} with them. |
| 34 |
* @param number the number of workers to create, positive |
| 35 |
* @param callback the callback to send worker instances to |
| 36 |
*/ |
| 37 |
void createWorkers(int number, @NonNull WorkerCallback callback); |
| 38 |
|
| 39 |
/** |
| 40 |
* The callback interface for the {@link SchedulerMultiWorkerSupport#createWorkers(int, WorkerCallback)} |
| 41 |
* method. |
| 42 |
*/ |
| 43 |
interface WorkerCallback { |
| 44 |
/** |
| 45 |
* Called with the Worker index and instance. |
| 46 |
* @param index the worker index, zero-based |
| 47 |
* @param worker the worker instance |
| 48 |
*/ |
| 49 |
void onWorker(int index, @NonNull Scheduler.Worker worker); |
| 50 |
} |
| 51 |
} |