# Rxohos **Repository Path**: HarmonyOS-tpc/Rxohos ## Basic Information - **Project Name**: Rxohos - **Description**: Reactive Extensions for openharmony specific bindings for RxJava3. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: 1.x - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 15 - **Forks**: 3 - **Created**: 2021-04-01 - **Last Updated**: 2025-05-18 ## Categories & Tags **Categories**: harmony **Tags**: None ## README ## Rxohos ## Introduction Rxohos: Reactive Extensions for openharmony specific bindings for RxJava3. This module adds the minimum classes to RxJava that make writing reactive components in openharmony applications easy and hassle-free. More specifically, it provides a Scheduler that schedules on the main thread or any given EventRunner. ## Usage instructions 1. A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the entity/ folder. 2. Observing on the main thread One of the most common operations when dealing with asynchronous tasks on openharmony is to observe the task's result or outcome on the main thread. With RxJava you would declare your Observable to be observed on the main thread: ``` Observable.just("one", "two", "three", "four", "five") .subscribeOn(Schedulers.newThread()) .observeOn(OpenHarmonySchedulers.mainThread()) .subscribe(/* an Observer */); ``` This will execute the Observable on a new thread, and emit results through onNext on the main thread. 3. Observing on arbitrary EventRunner The previous sample is merely a specialization of a more general concept: binding asynchronous communication to a openharmony message loop, or EventRunner. In order to observe an Observable on an arbitrary EventRunner, create an associated Scheduler by calling OpenHarmonySchedulers.from: ``` EventRunner backgroundeventRunner = EventRunner.create("backgroundThread"); Observable.just("one", "two", "three", "four", "five") .observeOn(OpenHarmonySchedulers.from(backgroundeventRunner)) .subscribe(/* an Observer */) ``` This will execute the Observable on a new thread, and emit results through onNext on whatever thread is running backgroundEventRunner. ## Installation instruction ``` Method 1: Generate the .har package through the library and add the .har package to the libs folder. Add the following code to the entry gradle: api 'io.reactivex.rxjava3:rxjava:3.0.3' implementation fileTree (dir: 'libs', include: ['*.jar', '*.har']) ``` Method 2: In project level build.gradle: allprojects{ repositories{ mavenCentral() } } ``` Add the following code to the entry gradle: ``` api 'io.reactivex.rxjava3:rxjava:3.0.3' implementation 'io.openharmony.tpc.thirdlib:Rxohos:1.0.0' ``` ## LICENSE Copyright 2015 The RxAndroid authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.