Skip to content

Instantly share code, notes, and snippets.

View adamw's full-sized avatar

Adam Warski adamw

View GitHub Profile
private val updateUserEndpoint = secureEndpoint.post
.in(User)
.in(jsonBody[UpdateUser_IN])
.out(jsonBody[UpdateUser_OUT])
.serverLogic {
case (authData, data) =>
(for {
userId <- auth(authData)
_ <- userService.changeUser(userId, data.login, data.email).transact(xa)
} yield UpdateUser_OUT()).toOut
case class DBConfig(username: String, password: String, url: String,
migrateOnStart: Boolean, driver: String, connectThreadPoolSize: Int) {
override def toString: String =
s"DBConfig($username,***,$url,$migrateOnStart,$driver,$connectThreadPoolSize)"
}
case class HttpConfig(host: String, port: Int)
// ... other config classes ...
case class Config(db: DBConfig, api: HttpConfig, email: EmailConfig,
passwordReset: PasswordResetConfig, user: UserConfig)
trait EmailModule extends BaseModule {
lazy val emailService = new EmailService(idGenerator, emailSender, config.email, xa)
// the EmailService implements the EmailScheduler functionality - hence, creating
// an alias for this dependency
lazy val emailScheduler: EmailScheduler = emailService
lazy val emailTemplates = new EmailTemplates()
// depending on the configuration, creating the appropriate EmailSender instance
lazy val emailSender: EmailSender = if (config.email.mailgun.enabled) {
new MailgunEmailSender(config.email.mailgun)(sttpBackend)
} else if (config.email.smtp.enabled) {
{
"contractName": "Tender",
"abi": [
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
val ae = IO.effectAsync[Any, Throwable, Unit] { cb =>
ec3.submit(new Runnable {
override def run(): Unit = {
println(Thread.currentThread().getName + " (async)")
cb(IO.fail(new IllegalStateException()))
}
})
}
run("async shift error") {
run("async shift error") {
ae.guarantee(IO.shift(ec1)).guarantee(printThread)
}
/*
Outputs:
-- async shift error --
ec3-1-785992331 (async)
ec1-2-274064559
val ae = IO.async[Unit] { cb =>
ec3.submit(new Runnable {
override def run(): Unit = {
println(Thread.currentThread().getName + " (async)")
cb(Left(new IllegalStateException()))
}
})
}
run("async error") {
run("async shift") {
a *> IO.shift(ec1) *> printThread
}
/*
Outputs:
-- async shift --
ec3-1-785992331 (async)
ec1-2-274064559
import tapir.docs.openapi._
import tapir.openapi.circe.yaml._
val yaml = List(petEndpoint).toOpenAPI("Our pets", "1.0").toYaml
implicit val runtime: DefaultRuntime = new DefaultRuntime {}
val serve = BlazeServerBuilder[Task]
.bindHttp(8080, "localhost")
.withHttpApp(Router("/" -> service).orNotFound)
.serve
.compile
.drain
runtime.unsafeRun(serve)