-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66470a8
commit 1a39f00
Showing
4 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
modules/server/src/main/scala/gql/server/interpreter/Finally.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gql.server.interpreter | ||
|
||
import cats.implicits._ | ||
import cats.effect._ | ||
|
||
trait Finally[F[_]] { | ||
def rememberResource[A](fa: Resource[F, A]): F[Unit] | ||
|
||
def remember[A](fa: F[A]): F[Unit] = | ||
rememberResource(Resource.eval(fa)) | ||
} | ||
|
||
object Finally { | ||
def make[F[_]](implicit F: Concurrent[F]): Resource[F, Finally[F]] = | ||
Resource.make(F.ref(List.empty[F[Unit]]))(_.get.flatMap(_.sequence_)).map { state => | ||
new Finally[F] { | ||
def rememberResource[A](fa: Resource[F, A]): F[Unit] = | ||
F.uncancelable { poll => | ||
poll(fa.allocated).flatMap { case (_, release) => state.update(release :: _).void } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
modules/server/src/main/scala/gql/server/interpreter/Unsafe.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fs2 | ||
|
||
import fs2.internal.Scope | ||
import cats.effect.Resource | ||
import cats._ | ||
import cats.implicits._ | ||
|
||
object UnsafeFs2Access { | ||
def getScope[F[_]]: Pull[F, Nothing, Scope[F]] = Pull.getScope[F] | ||
|
||
def leaseScope[F[_]: MonadThrow]: Pull[F, Nothing, Resource[F, Unit]] = | ||
getScope[F].map(scope => Resource.make(scope.lease)(x => x.cancel.rethrow).void) | ||
} |