Skip to content

Commit 6cf9bf9

Browse files
committed
replaced getOne method which is based on promise with toBlocking.first
1 parent 4bda5f4 commit 6cf9bf9

File tree

1 file changed

+3
-17
lines changed
  • rxjava-contrib/rxjava-scalaz/src/main/scala/rx/lang/scala/scalaz

1 file changed

+3
-17
lines changed

rxjava-contrib/rxjava-scalaz/src/main/scala/rx/lang/scala/scalaz/package.scala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package rx.lang.scala
1818
import scala.language.higherKinds
1919
import _root_.scalaz._
2020
import _root_.scalaz.Tags.{Zip => TZip}
21-
import scala.concurrent._
22-
import scala.concurrent.duration._
2321

2422
/**
2523
* This package object provides some type class instances for Observable.
@@ -47,26 +45,14 @@ package object scalaz {
4745
override def zip[A, B](a: => Observable[A], b: => Observable[B]): Observable[(A, B)] = a zip b
4846

4947
// IsEmpty (NOTE: This method is blocking call)
50-
override def isEmpty[A](fa: Observable[A]): Boolean = getOne(fa.isEmpty)
48+
override def isEmpty[A](fa: Observable[A]): Boolean = fa.isEmpty.toBlocking.first
5149

5250
// Traverse (NOTE: This method is blocking call)
5351
override def traverseImpl[G[_], A, B](fa: Observable[A])(f: (A) => G[B])(implicit G: Applicative[G]): G[Observable[B]] = {
5452
val seed: G[Observable[B]] = G.point(Observable.empty)
55-
getOne(fa.foldLeft(seed) {
53+
fa.foldLeft(seed) {
5654
(ys, x) => G.apply2(ys, f(x))((bs, b) => bs :+ b)
57-
}.head)
58-
}
59-
60-
// This method extracts first elements from Observable.
61-
// NOTE: Make sure that 'o' has at least one element.
62-
private[this] def getOne[T](o: Observable[T]): T = {
63-
val p = Promise[T]
64-
val sub = o.first.subscribe(p.success(_))
65-
try {
66-
Await.result(p.future, Duration.Inf)
67-
} finally {
68-
sub.unsubscribe()
69-
}
55+
}.toBlocking.first
7056
}
7157
}
7258

0 commit comments

Comments
 (0)