Skip to content

Instantly share code, notes, and snippets.

View TimWSpence's full-sized avatar

Tim Spence TimWSpence

View GitHub Profile
//> using scala 3
//> using toolkit typelevel:default
import cats.syntax.all.*
import cats.effect.*
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.*
import org.http4s.circe.CirceEntityDecoder.*
import org.http4s.implicits.*
import org.http4s.headers.Authorization
@TimWSpence
TimWSpence / lift_hang.scala
Created November 17, 2023 11:40
Minimization of hanging caused by canceling a Doobie transaction whilst inside `WeakAsync.liftK`
//> using scala "3.3.1"
//> using dep "org.typelevel::cats-effect::3.5.2"
import cats.*
import cats.syntax.all.*
import cats.effect.*
import cats.effect.std.Dispatcher
import scala.concurrent.duration.*
UnauthorizedAccessException: Access to the path "/private/var/folders/dr/hhydhgf570g59xhljl0l0mkm0000gn/T/AppTranslocation/3231433E-CA2C-435B-BD58-0049DADD6331/d/MapNuke.app/Contents/Export/mapnuke1.map" is denied.
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <319b5411003b47fbaceecace494b6f79>:0)
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize) (at <319b5411003b47fbaceecace494b6f79>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int)
System.IO.File.Create (System.String path, System.Int32 bufferSize) (at <319b5411003b47fbaceecace494b6f79>:0)
System.IO.File.Create (System.String path) (at <319b5411003b47fbaceecace494b6f79>:0)
MapFileWriter.GenerateText (
//> using scala "3.2.1"
//> using lib "org.typelevel::cats-effect-testkit:3.4.0"
//> using lib "org.typelevel::munit-cats-effect-3:1.0.7"
import cats.effect.*
import cats.effect.testkit.TestControl
import munit.CatsEffectSuite
import scala.concurrent.duration.*
class Suite extends CatsEffectSuite:
let Tree
: Type → Type
= λ(Elem : Type) →
∀(T : Type) → ∀(Branch : Elem → T → T → T) → ∀(Leaf : T) → T
let showTree =
λ(elem : Type) →
λ(show : elem → Text) →
λ(tree : Tree elem) →
tree
@TimWSpence
TimWSpence / blockOn.scala
Last active April 28, 2023 13:42
Cats effect 2 nested evalOn/blockOn gotcha
import cats.implicits._
import cats.effect.{Blocker, IO, IOApp, ExitCode}
import java.util.concurrent.Executors
object Test extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val blocker = Blocker.liftExecutorService(Executors.newCachedThreadPool())
blocker.blockOn(
for {
_ <- printThread
import cats.effect.{ExitCode, IO, IOApp}
import io.github.timwspence.cats.stm.{TVar, STM}
import scala.concurrent.duration._

object Main extends IOApp {

  override def run(args: List[String]): IO[ExitCode] =
    for {
      accountForTim   <- TVar.of[Long](100).commit[IO]
def atomically[F[_], A](s: STM[A]): F[A]
def get: STM[A]
def set(a: A): STM[Unit]
def modify(f: A => A): STM[Unit]
def map[A, B](s: STM[A], f: A => B): STM[B]
def orElse[A](attempt: STM[A], fallback: STM[A]): STM[A]
def check(check: => Boolean): STM[Unit]