RAII resource management system
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
java/tech/resource 4.2 Jan 16, 2019
src/tech
test/tech Of course closeable works... Feb 3, 2019
.gitignore Moving to deps.edn where possible. Dec 30, 2018
.travis.yml travis Dec 30, 2018
README.md editing Jan 16, 2019
deps.edn
project.clj snap Jan 16, 2019

README.md

tech.resource

Clojars Project

Generic thread-safe and exception-safe non-gc or 'off heap' resource management.

There is some more information on our blog.

;;create the file
(defn new-random-file
  [fname]
  (resource/track (RandomAccessFile. fname) #(.close item)))


;;Use it
(resource/stack-resource-context
  (let [f (new-random-file fname)]
    ...
    ))

;;Similar to with-open, this will close the file regardless
;;of what happens.  The advantage is this can map to anything
;;you can implement the resource protocol with meaning network sockets,
;;JNI pointers, GPU contexts, etc.  It is also possible to have the
;;gc track something if the dispose functionality does not reference
;;the item itself.

(let [f (resource/track (double-array [1 2 3]) #(println "disposed") :gc)]
  ...)
;;Disposed will print when the gc determines the double array is no longer
;;reachable

There are now explicit methods to create either a weak or soft reference. For the differences, see here.

Usage

Checkout the stack and gc tests.

Or take a giant leap and check out tvm-clj.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. Complements of Tech Ascent, LLC.