• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

scoverage / sbt-scoverage-samples / 4741723636

19 Apr 2023 09:30AM CUT coverage: 66.912% (-5.6%) from 72.477%
4741723636

push

Roland Tritsch
Even more time to shut down.

91 of 136 relevant lines covered (66.91%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/main/scala/org/scoverage/samples/Futures.scala
1
package org.scoverage.samples
2

3
import scala.concurrent.{Promise, Future, ExecutionContext}
4
import scala.language.implicitConversions
5

6
class Futures {
7

8
  import EitherMappableFuture._
9

1✔
10
  def insert[T](
11
      doc: T
12
  )(implicit name: String, executor: ExecutionContext): Future[Result] = {
1✔
13
    val promise = Promise[Result]()
×
14
    Future {
×
15
      Thread.sleep(300)
1✔
16
    }.onComplete { case _ =>
1✔
17
      promise.success(Result(true, 421))
18
    }
×
19
    promise.future.mapEither(meaningful)
20
  }
21

×
22
  def check(result: Result): Either[Exception, Result] = Right(result)
23

1✔
24
  def meaningful(result: Result) = {
1✔
25
    check(result) match {
×
26
      case Left(e)  => Left(e)
1✔
27
      case Right(r) => Right(r)
28
    }
29
  }
30
}
31

32
case class Result(
×
33
    success: Boolean = true,
×
34
    status: Int = 200,
1✔
35
    timestamp: Long = System.currentTimeMillis
36
)
37

38
case class EitherMappableFuture[A](future: Future[A]) {
1✔
39
  def mapEither[E <: Throwable, B](
40
      f: A => Either[E, B]
41
  )(implicit ec: ExecutionContext): Future[B] = {
1✔
42
    future.flatMap(f(_) match {
×
43
      case Left(e)  => Future.failed(e)
1✔
44
      case Right(b) => Future.successful(b)
45
    })
46
  }
47
}
48
object EitherMappableFuture {
1✔
49
  implicit def futureToEitherMappable[A](
50
      future: Future[A]
51
  ): EitherMappableFuture[A] = EitherMappableFuture(future)
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc