Я видел большинство примеров использования Executor в классах DataSource, которые обычно передаются в DataSourceFactory из ViewModel, а затем в классы DataSource. Как мне использовать executor. Какие преимущества/преимущества использования Executor.
МОДЕЛЬ ПРЕДСТАВЛЕНИЯ
public FooViewModel{
public FooViewModel() {
executor = Executors.newFixedThreadPool(5);
//pasing executor here.
FooDataSourceFactory itemDataSourceFactory = new
FooDataSourceFactory(executor);
}
DATASORUCEFACTORY
public class FooDataSourceFactory extends DataSource.Factory {
private FooDataSource itemDataSource;
private Executor executor;
//creating the mutable live data
private MutableLiveData itemLiveDataSource = new
MutableLiveData();
public FooDataSourceFactory(Executor executor) {
this.executor = executor;
}
@Override
public DataSource create() {
//passing executor here..
itemDataSource = new FooDataSource(executor);
//posting the dataSource to get the values
itemLiveDataSource.postValue(itemDataSource);
//returning the dataSource
return itemDataSource;
.................
}
ИСТОЧНИК ДАННЫХ
public class FooDataSource {
FooDataSource(Executor executor){
//don't know what to do with executor
}
}
Подробнее здесь: https://stackoverflow.com/questions/554 ... ng-library