use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableConcatTest method concatNonBlockingObservables.
@Test
public void concatNonBlockingObservables() {
final CountDownLatch okToContinueW1 = new CountDownLatch(1);
final CountDownLatch okToContinueW2 = new CountDownLatch(1);
final TestObservable<String> w1 = new TestObservable<>(null, okToContinueW1, "one", "two", "three");
final TestObservable<String> w2 = new TestObservable<>(null, okToContinueW2, "four", "five", "six");
Observer<String> observer = TestHelper.mockObserver();
Observable<Observable<String>> observableOfObservables = Observable.unsafeCreate(new ObservableSource<Observable<String>>() {
@Override
public void subscribe(Observer<? super Observable<String>> observer) {
observer.onSubscribe(Disposable.empty());
// simulate what would happen in an Observable
observer.onNext(Observable.unsafeCreate(w1));
observer.onNext(Observable.unsafeCreate(w2));
observer.onComplete();
}
});
Observable<String> concat = Observable.concat(observableOfObservables);
concat.subscribe(observer);
verify(observer, times(0)).onComplete();
try {
// release both threads
okToContinueW1.countDown();
okToContinueW2.countDown();
// wait for both to finish
w1.t.join();
w2.t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(1)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(1)).onNext("four");
inOrder.verify(observer, times(1)).onNext("five");
inOrder.verify(observer, times(1)).onNext("six");
verify(observer, times(1)).onComplete();
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableConcatMapEagerTest method concatArrayEager.
@SuppressWarnings("unchecked")
@Test
public void concatArrayEager() throws Exception {
for (int i = 2; i < 10; i++) {
Observable<Integer>[] obs = new Observable[i];
Arrays.fill(obs, Observable.just(1));
Integer[] expected = new Integer[i];
Arrays.fill(expected, 1);
Method m = Observable.class.getMethod("concatArrayEager", ObservableSource[].class);
TestObserver<Integer> to = TestObserver.create();
((Observable<Integer>) m.invoke(null, new Object[] { obs })).subscribe(to);
to.assertValues(expected);
to.assertNoErrors();
to.assertComplete();
}
}
use of io.reactivex.rxjava3.core.ObservableSource in project AgileDev by LZ9.
the class DrawerTestActivity method refreshTitle.
/**
* 刷新称号
*/
private void refreshTitle() {
int random = new Random().nextInt(TITLES.length);
Observable.just(TITLES[random]).flatMap(new Function<String, ObservableSource<String>>() {
@Override
public ObservableSource<String> apply(String s) throws Exception {
Thread.sleep(1000);
return Observable.just(s);
}
}).compose(RxUtils.<String>ioToMainObservable()).compose(this.<String>bindUntilEvent(ActivityEvent.DESTROY)).subscribe(new ProgressObserver<String>() {
@Override
public void onPgNext(String title) {
StringBuilder stringBuilder = new StringBuilder();
mTitleTv.setText(stringBuilder.append("称号:").append(title));
ToastUtils.showShort(getContext(), "已为您刷新称号");
}
@Override
public void onPgError(Throwable e, boolean isNetwork) {
ToastUtils.showShort(getContext(), "刷新失败");
}
}.create(getContext(), "正在为您刷新称号", false));
}
use of io.reactivex.rxjava3.core.ObservableSource in project quran_android by quran.
the class AudioManagerUtils method shuyookhDownloadObservable.
@NonNull
public static Single<List<QariDownloadInfo>> shuyookhDownloadObservable(QuranInfo quranInfo, String basePath, List<QariItem> qariItems) {
return Observable.fromIterable(qariItems).flatMap((Function<QariItem, ObservableSource<QariDownloadInfo>>) item -> {
QariDownloadInfo cached = cache.get(item);
if (cached != null) {
return Observable.just(cached);
}
File baseFile = new File(basePath, item.getPath());
return !baseFile.exists() ? Observable.just(new QariDownloadInfo(item)) : item.isGapless() ? getGaplessSheikhObservable(baseFile, item).toObservable() : getGappedSheikhObservable(quranInfo, baseFile, item).toObservable();
}).doOnNext(qariDownloadInfo -> cache.put(qariDownloadInfo.qariItem, qariDownloadInfo)).toList().subscribeOn(Schedulers.io());
}
use of io.reactivex.rxjava3.core.ObservableSource in project Mycat2 by MyCATApache.
the class GroupByKeyPlan method execute.
@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
List<Field> fields = schema().getFields();
InnerType[] innerTypes = schema().getFields().stream().map(i -> InnerType.from(i.getType())).toArray(n -> new InnerType[n]);
Map map = MapFactory.createMap(innerTypes);
RecordSink[] recordSinks = new RecordSink[groupByKeys.length];
int groupIndex = 0;
for (GroupKeys groupByKey : groupByKeys) {
IntInnerType[] intPairs = new IntInnerType[groupByKey.getKeys().length];
int[] keys = groupByKey.getKeys();
int index = 0;
for (int key : keys) {
Field field = fields.get(key);
intPairs[index] = IntInnerType.of(index, InnerType.from(field.getType()));
index++;
}
recordSinks[groupIndex] = RecordSinkFactory.INSTANCE.buildRecordSink(intPairs);
groupIndex++;
}
return inputPlan.execute(rootContext).flatMap(new Function<VectorSchemaRoot, ObservableSource<? extends VectorSchemaRoot>>() {
@Override
public ObservableSource<? extends VectorSchemaRoot> apply(VectorSchemaRoot input) throws Throwable {
int rowCount = input.getRowCount();
VectorBatchRecord record = new VectorBatchRecord(input);
VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema, rowCount * recordSinks.length);
int outputRowId = 0;
for (int i = 0; i < recordSinks.length; i++) {
RecordSink recordSink = recordSinks[i];
for (int rowId = 0; rowId < rowCount; rowId++) {
record.setPosition(rowId);
MapKey key = map.withKey();
RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
recordSink.copy(record, recordSinkSPI);
if (key.create()) {
recordSink.copy(record, outputRowId, output);
outputRowId++;
// output
} else {
// skip
}
}
}
if (outputRowId == 0) {
output.close();
return Observable.empty();
}
output.setRowCount(outputRowId);
inputPlan.eachFree(input);
return Observable.fromArray(output);
}
}).doOnComplete(new Action() {
@Override
public void run() throws Throwable {
map.close();
}
});
}
Aggregations