Skip to content

Commit

Permalink
Make executor use daemon threads
Browse files Browse the repository at this point in the history
  • Loading branch information
nrktkt committed Mar 10, 2021
1 parent b25fb24 commit 5d1f66a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ So for example you could synchronously validate a JWT with some custom claims wi
<sauce-code
repo='blackdoor/jose'
file='docs/src/black/door/jose/docs/SampleCode.scala'
lines='64:76'
lines='64:77'
></sauce-code>
---
> Not yet implemented:
> * JWK serialization partly implemented
> * JWE
Expand Down
21 changes: 13 additions & 8 deletions jose/src/black/door/jose/jwt/Jwt.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package black.door.jose.jwt

import black.door.jose.{ByteDeserializer, ByteSerializer}

import java.security.KeyException
import java.util.concurrent.{Executors, TimeUnit}
import cats.data.{EitherT, OptionT}
import cats.implicits._
import black.door.jose.jwa.{SignatureAlgorithm, SignatureAlgorithms}
import black.door.jose.jwk.Jwk
import black.door.jose.jws._
import black.door.jose.{ByteDeserializer, ByteSerializer}
import cats.data.{EitherT, OptionT}
import cats.implicits._

import java.security.KeyException
import java.util.concurrent.{Executors, TimeUnit}
import scala.collection.immutable.Seq
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}
Expand Down Expand Up @@ -68,8 +67,14 @@ object Jwt {
OptionT(jwtValidator.orElse(fallbackJwtValidator).apply(jwt)).toLeft(jwt)
}.value

private val threadFactory = Executors.defaultThreadFactory()

private val sadSpasticLittleEc =
ExecutionContext.fromExecutorService(Executors.newCachedThreadPool)
ExecutionContext.fromExecutor(Executors.newCachedThreadPool { r =>
val t = threadFactory.newThread(r)
t.setDaemon(true)
t
})

def validate(compact: String) = new UnitValidation(compact)

Expand Down Expand Up @@ -110,7 +115,7 @@ object Jwt {
headerDeserializer,
sadSpasticLittleEc
),
Duration(1, TimeUnit.SECONDS)
Duration(5, TimeUnit.SECONDS)
)

def async(implicit ec: ExecutionContext) =
Expand Down

0 comments on commit 5d1f66a

Please sign in to comment.