Skip to content

Commit

Permalink
Fix ValueMagnet implicit conversion
Browse files Browse the repository at this point in the history
The block we convert into a ValueMagnet can throw, in which case we
won't produce a ValueMagnet. I think we want to be safe and produce a
ValueMagnet with a failed Future in those scenarios.
  • Loading branch information
jcazevedo committed Jun 17, 2024
1 parent 27efb79 commit 924beb4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion caching/src/main/scala/com/velocidi/apso/caching/Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.velocidi.apso.caching

import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.Try
import scala.util.control.NonFatal

/** General interface implemented by all spray cache implementations.
Expand Down Expand Up @@ -90,6 +91,6 @@ trait Cache[V] { cache =>

class ValueMagnet[V](val future: Future[V])
object ValueMagnet {
implicit def fromAny[V](block: V): ValueMagnet[V] = fromFuture(Future.successful(block))
implicit def fromAny[V](block: => V): ValueMagnet[V] = fromFuture(Future.fromTry(Try(block)))
implicit def fromFuture[V](future: Future[V]): ValueMagnet[V] = new ValueMagnet(future)
}

0 comments on commit 924beb4

Please sign in to comment.