Created
January 26, 2018 11:43
-
-
Save vorobeij/03ff903a9ad75970844704cb7fb659e6 to your computer and use it in GitHub Desktop.
perform task for each element in list in many threads with rxjava2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // perform task for each element in list in many threads with rxjava2 | |
| fun getAppsList2(): Single<MutableList<UserApp>>? { | |
| val pm = context.packageManager | |
| val packages = pm.getInstalledApplications(PackageManager.GET_META_DATA) | |
| val tasks: MutableList<ApplicationInfo> = mutableListOf() | |
| packages.mapTo(tasks) { it } | |
| return Observable.fromIterable(tasks) | |
| .map { appInfo -> | |
| Observable.fromCallable { | |
| val name = appInfo.packageName | |
| val label = appInfo.loadLabel(pm).toString() | |
| UserApp(name, label) | |
| } | |
| }.map { task -> task.subscribeOn(Schedulers.io()) } | |
| .flatMap { t -> t } | |
| .toList() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment