repo for my hex addons :3
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

aperture science

+35
+1
util/changelog
··· 1 + 0.1.2 add portals 1 2 0.1.2 intrusive holder allocation tracking
+34
util/src/main/scala/org/eu/net/pool/phlib/aperture.scala
··· 1 + package org.eu.net.pool 2 + package phlib 3 + 4 + import java.util.NoSuchElementException 5 + import scala.util.{Failure, Success, Try, boundary} 6 + 7 + class Scope[T](initial: T): 8 + private object local extends InheritableThreadLocal[Option[T]]: 9 + override def initialValue: Option[T] = None 10 + def enter[R](newValue: T)(body: => R): R = 11 + val oldValue = local.get 12 + try 13 + local.set(Some(newValue)) 14 + body 15 + finally 16 + local.set(oldValue) 17 + def value: T = local.get.getOrElse(initial) 18 + def valueIfChanged: Option[T] = local.get 19 + def isChanged: Boolean = local.get.isDefined 20 + object Scope: 21 + given [T] => Conversion[Scope[T], T] = _.value 22 + 23 + class Portal[T]: 24 + private val scope = Scope[Try[T] => Nothing]: 25 + case Success(value) => sys.exit(0) 26 + case Failure(exc) => { exc.printStackTrace(); sys.exit(1) } 27 + def enter[R](body: => R): Either[T, R] = 28 + def wrap: Either[Try[T], R] = scope.enter(x => return Left(x))(Right(body)) 29 + wrap.left.map(_.get) 30 + def isEntered: Boolean = scope.isChanged 31 + def exit(value: T): Nothing = scope(Success(value)) 32 + def abort(error: Throwable): Nothing = scope(Failure(error)) 33 + def tryExit(value: T): Unit = for jump <- scope.valueIfChanged do jump(Success(value)) 34 + def tryAbort(error: Throwable): Unit = for jump <- scope.valueIfChanged do jump(Failure(error))