一些简单的rxscala代码:
val s = Observable.interval(Duration("100 millis"))
.zip(Seq(1, 2, 3)).map(_._2).delay(Duration("2 s"))
println(s.toBlocking.toList)
运行时,会抛出异常:
Exception in thread "main" java.util.NoSuchElementException: next on empty iterator
at scala.collection.Iterator$$anon$2.next(Iterator.scala:39)
at scala.collection.Iterator$$anon$2.next(Iterator.scala:37)
at scala.collection.LinearSeqLike$$anon$1.next(LinearSeqLike.scala:47)
at scala.collection.convert.Wrappers$IteratorWrapper.next(Wrappers.scala:31)
at rx.internal.operators.OperatorZipIterable$1.onNext(OperatorZipIterable.java:65)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
at rx.internal.operators.OnSubscribeTimerPeriodically$1.call(OnSubscribeTimerPeriodically.java:51)
at rx.Scheduler$Worker$1.call(Scheduler.java:120)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
哪里错了?
答案 0 :(得分:1)
这是RxJava中的一个错误。它已在https://github.com/ReactiveX/RxJava/pull/3528中修复,您必须等待下一个版本。但是,您可以使用Observable.interval(Duration("100 millis")).zip(Observable.from(Seq(1, 2, 3))).map(_._2).delay(Duration("2 s"))
作为解决方法。