Tag: rx kotlin

Rx-Kotlin awaitTerminalEvent永远不会完成

我想更好地了解如何使用Rx-Kotlin进行单元测试,但是我还没有能够成功地将主题设置为“完成”。 因此,我总是等待5秒的时间(onComplete应该立即),然后在assertComplete上失败。 我对awaitTerminalEvent的理解是,它应该只阻塞,直到onComplete被调用。 我也看了一下TestScheduler,但是我不认为应该在这里需要。 任何帮助或文件,可以带领我在正确的方向将不胜感激。 @Test fun testObservable() { val subject = BehaviorSubject.create<Int>() subject.onNext(0) TestSubscriber<Int>().apply { subject.subscribe({ System.out.println(it) subject.onNext(1) subject.onComplete() }) this.awaitTerminalEvent(5, TimeUnit.SECONDS) this.assertComplete() this.assertValue(1) } }

在Kotlin中使用Flowable的多个改进2请求

为了提高我在kotlin,Rx,Retrofit2方面的技能,我决定做一个演示项目。 演示项目包括在回收站视图中显示帖子,然后在详细活动中显示帖子的详细信息。 我遇到了显示来自不同API调用的数据的困难:用户名,标题,帖子正文以及帖子的评论数量。 我的问题是,我想要做多个请求,然后获取所需的所有数据,以便在详细的活动中显示它们。 这意味着做一个电话,给我的用户名,然后打电话给我的帖子的评论数。 帖子的标题和正文来自于主要活动中的一个请求,我只是把它传递给详细的活动。 Api调用: //返回帖子的评论1 http://jsonplaceholder.typicode.com/comments?postId=1 //返回用户2的信息 http://jsonplaceholder.typicode.com/users/2 //调用用于显示主要活动中的帖子 HTTP:/jsonplaceholder.typicode.com/posts 我还是Rx上的新手,我正在考虑使用flatMap,但我不知道如何在kotlin中使用Flowable。 var post = viewModel.getPost() var userStream: Flowable<User> = postService.getUser(post.userId) var commentsByPostIdCall: Flowable<List<Comment>> = postService.getCommentsByPostId(post.id) userStream.subscribeOn(Schedulers.io()) .subscribe(object : Subscriber<User> { override fun onError(t: Throwable?) { Log.d(this.toString(), " Read of users failed with the following message: " + t?.message); } override fun onNext(user: […]

Kotlin库'rxkotlin-0.21.0.jar'具有不受支持的格式。 请更新库或插件

标题中的错误出现在Android Studio中,作为警告栏,高于我的所有代码: Android Studio版本: 1.1.0 Android Studio的Kotlin插件版本: 0.11.91.AndroidStudio.4 build.gradle文件似乎正在使用所有最新版本的Kotlin库: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "ca.amandeep.simpletransit" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets { main.java.srcDirs += 'src/main/kotlin' } } dependencies { compile […]

在Kotlin函数类型中表示“超级”泛型?

我试图移植一个RxJava库,并利用Kotlin的扩展功能。 fun <T,R: MutableCollection<T>> Observable<T>.collectWhile(factory: (() -> R), condition: (R,T) -> Boolean) = compose(Transformers.collectWhile(factory,condition)) Transformers.collectWhile()是用Java编写的,具有以下签名: public static <T, R extends Collection<T>> Transformer<T, R> collectWhile(final Func0<R> factory, final Action2<? super R, ? super T> collect) 但是,我正在collect关于collect参数的映射问题,而且我不擅长泛型。 我如何用功能类型来表达super ? UPDATE 我愚蠢的错误。 我不应该在深夜发帖。 我其实是针对这个 public static <T, R extends Iterable<?>> Transformer<T, R> collectWhile(final Func0<R> factory, final Action2<? super […]

在Kotlin for Android中编程时使用RxAndroid或RxKotlin?

我将开始在我的Android项目中使用反应式编程。 我使用Kotlin作为主要语言,现在我想申请Rx。 我的第一个选择是RxAndroid,但是我注意到有RxKotlin。 据我所知,两者都是从RxJava分支的,所以RxAndroid可能为android常见任务提供了一些API。 另一方面,RxKotlin支持开箱即用,并允许我避免与java混合使用kotlin。 在这种情况下,哪一个是首选的库?

Spring 5和Kotlin 1.1协程:类型rx.Scheduler不存在

我正在使用Kotlin 1.1.4-3和Spring-context 5.0.0.RELEASE。 在启动项目,我得到这个错误: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'coroutineAnnotationBeanPostProcessor' defined in class path resource [org/springframework/kotlin/experimental/coroutine/context/ProxyCoroutineConfiguration.class]: Unsatisfied dependency expressed through method 'coroutineAnnotationBeanPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalCoroutineContextResolver' defined in class path resource [org/springframework/kotlin/experimental/coroutine/context/CoroutineContextResolverConfiguration.class]: Unexpected exception during bean creation; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:458) at […]

Rxjava与kotlin

我在kotlin中使用rxjava 2,但它不是编译我应该如何解决它? var emailField = name.textChanges().skipInitialValue().toFlowable(BackpressureStrategy.LATEST) var passField = password.textChanges().skipInitialValue().toFlowable(BackpressureStrategy.LATEST) Flowable.combineLatest(emailField,passField, BiFunction { t1, t2 -> t1.isNotEmpty() && t2.isNotEmpty() })

Kotlin协同程序如何比RxKotlin更好?

我为什么要使用Kotlin协同程序? RxKotlin库似乎更为复杂。 Kotlin协同程序看起来不那么强大,而且比较麻烦。 我根据安德烈·布雷斯拉夫(JetBrains)的这个设计演讲,在协同工作的基础上: https : //www.youtube.com/watch?v = 4W3ruTWUhpw 幻灯片从谈话是可以访问这里: https : //www.slideshare.net/abreslav/jvmls-2016-coroutines-in-kotlin