Skip to content

Instantly share code, notes, and snippets.

@nhibberd
Created December 24, 2014 04:32
Show Gist options
  • Save nhibberd/1a528b59c471df741b53 to your computer and use it in GitHub Desktop.
Save nhibberd/1a528b59c471df741b53 to your computer and use it in GitHub Desktop.
TestingTemporaries
case class TestingTemporaries(buffer: java.util.concurrent.ConcurrentLinkedQueue[LocalPath])
object TestingTemporaries {
val registered: java.util.concurrent.atomic.AtomicReference[TestingTemporaries] =
new java.util.concurrent.atomic.AtomicReference[TestingTemporaries]
def localPath: RIO[LocalPath] = ResultT.io {
if (registered.compareAndSet(null, TestingTemporaries(new java.util.concurrent.ConcurrentLinkedQueue)))
Runtime.getRuntime.addShutdownHook(new Thread(new Runnable {
def run: Unit = {
// TODO delete all the things
}
}))
val temporaries = registered.get
val p = LocalPath(uniqueLocalPath)
temporaries.buffer.add(p)
p
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment