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

scoverage / sbt-scoverage-samples / #60

08 Apr 2023 02:29AM CUT coverage: 71.963% (+7.3%) from 64.706%
#60

push

rolandtritsch
Even more time to shut down.

77 of 107 relevant lines covered (71.96%)

0.72 hits per line

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

88.89
/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

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

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

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

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

38
case class EitherMappableFuture[A](future: Future[A]) {
39
  def mapEither[E <: Throwable, B](
40
      f: A => Either[E, B]
41
  )(implicit ec: ExecutionContext): Future[B] = {
42
    future.flatMap(f(_) match {
1✔
43
      case Left(e)  => Future.failed(e)
44
      case Right(b) => Future.successful(b)
45
    })
46
  }
47
}
48
object EitherMappableFuture {
49
  implicit def futureToEitherMappable[A](
50
      future: Future[A]
51
  ): EitherMappableFuture[A] = EitherMappableFuture(future)
1✔
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