Skip to content

Instantly share code, notes, and snippets.

@vigneshwaranr
Last active February 14, 2021 08:14
Show Gist options
  • Save vigneshwaranr/ce75246f8b9e8a23c057bb5f6d3362e1 to your computer and use it in GitHub Desktop.
Save vigneshwaranr/ce75246f8b9e8a23c057bb5f6d3362e1 to your computer and use it in GitHub Desktop.
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ExecutionContext, Future}
trait Request
trait Response
trait CacheService {
def isDuplicateRequest(request: Request)(implicit ec: ExecutionContext): Future[Option[Request]]
def setCacheForDeduplication(dedupedReq: Option[Request])(implicit ec: ExecutionContext): Future[Boolean]
}
trait Processor {
def process(request: Option[Request])(implicit ec: ExecutionContext): Future[Response]
}
class API(cacheService: CacheService, processor: Processor) {
def process(request: Request): Future[Response] = {
for {
dedupedRequest <- cacheService.isDuplicateRequest(request)
response <- processor.process(dedupedRequest)
_ <- cacheService.setCacheForDeduplication(dedupedRequest) // what's wrong here?
} yield response
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment