Liking cljdoc? Tell your friends :D

tech.resource

Clojars Project

Generic thread-safe and exception-safe resource management.

(extend-protocol resource/PResource
  RandomAccessFile
  (release-resource [^RandomAccessFile item] (.close item)))

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


;;Use it

(resource/with-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.

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

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close