Skip to content

Commit 0d69f66

Browse files
committed
Monix extensions - move broken test to jvm only
1 parent e8f8e74 commit 0d69f66

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.avsystem.commons
2+
package concurrent
3+
4+
import monix.eval.Task
5+
import monix.execution.Scheduler
6+
import org.scalatest.concurrent.ScalaFutures
7+
import org.scalatest.funsuite.AnyFunSuite
8+
import org.scalatest.matchers.should.Matchers
9+
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
10+
11+
import scala.concurrent.TimeoutException
12+
import scala.concurrent.duration._
13+
14+
class JvmTaskExtensionsTest extends AnyFunSuite with Matchers with ScalaCheckDrivenPropertyChecks with ScalaFutures {
15+
16+
import com.avsystem.commons.concurrent.TaskExtensions._
17+
18+
private implicit val scheduler: Scheduler = Scheduler.global
19+
20+
// This test does not work in SJS runtime (but the method itself does)
21+
test("lazyTimeout") {
22+
val result = Task.never.lazyTimeout(50.millis, "Lazy timeout").runToFuture.failed.futureValue
23+
result shouldBe a[TimeoutException]
24+
result.getMessage shouldBe "Lazy timeout"
25+
}
26+
}

core/src/main/scala/com/avsystem/commons/concurrent/TaskExtensions.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package concurrent
44
import com.avsystem.commons.concurrent.TaskExtensions.{TaskCompanionOps, TaskOps}
55
import com.avsystem.commons.misc.Timestamp
66
import monix.eval.Task
7+
import monix.reactive.Observable
78

89
import java.util.concurrent.TimeUnit
910
import scala.concurrent.TimeoutException
@@ -37,6 +38,8 @@ object TaskExtensions extends TaskExtensions {
3738
}
3839

3940
object TaskCompanionOps {
41+
import com.avsystem.commons.concurrent.ObservableExtensions.observableOps
42+
4043
/** A [[Task]] of [[Opt.Empty]] */
4144
def optEmpty[A]: Task[Opt[A]] = Task.pure(Opt.Empty)
4245

@@ -49,7 +52,7 @@ object TaskExtensions extends TaskExtensions {
4952
}
5053

5154
def traverseMap[K, V, A, B](map: Map[K, V])(f: (K, V) => Task[(A, B)]): Task[Map[A, B]] =
52-
Task.traverse(map.toSeq)({ case (key, value) => f(key, value) }).map(_.toMap)
55+
Observable.fromIterable(map).mapEval({ case (key, value) => f(key, value) }).toL(Map)
5356

5457
def traverseMapValues[K, A, B](map: Map[K, A])(f: (K, A) => Task[B]): Task[Map[K, B]] =
5558
traverseMap(map)({ case (key, value) => f(key, value).map(key -> _) })

core/src/test/scala/com/avsystem/commons/concurrent/TaskExtensionsTest.scala

-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,11 @@ import org.scalatest.funsuite.AnyFunSuite
88
import org.scalatest.matchers.should.Matchers
99
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
1010

11-
import scala.concurrent.TimeoutException
12-
import scala.concurrent.duration._
13-
1411
class TaskExtensionsTest extends AnyFunSuite with Matchers with ScalaCheckDrivenPropertyChecks with ScalaFutures {
1512
import com.avsystem.commons.concurrent.TaskExtensions._
1613

1714
private implicit val scheduler: Scheduler = Scheduler.global
1815

19-
test("lazyTimeout") {
20-
val result = Task.never.lazyTimeout(50.millis, "Lazy timeout").runToFuture.failed.futureValue
21-
result shouldBe a[TimeoutException]
22-
result.getMessage shouldBe "Lazy timeout"
23-
}
24-
2516
test("traverseOpt") {
2617
Task.traverseOpt(Opt.empty[Int])(i => Task.now(i)).runToFuture.futureValue shouldBe Opt.Empty
2718
Task.traverseOpt(Opt.some(123))(i => Task.now(i)).runToFuture.futureValue shouldBe Opt.some(123)

0 commit comments

Comments
 (0)