README.org
January 18, 2014 · View on GitHub
#+STARTUP: hidestars showall
-
scopes A little library for resource scopes.
When used with Java 7, scopes will take advantage of the
java.lang.AutoCloseableinterface and the suppressed exception features ofjava.lang.Throwable.When used with Java 6, if—in response to an exception from the body of the
with-resource-scopemacro—an exception occurs trying to close a resource, then it will be swallowed up.For example:
: (with-resource-scope : (scoped-thunk! #(throw (Exception. "bar"))) : (throw (Exception. "foo")))
The "foo" exception will propagate from the body of the
with-resource-scope. In the case of Java 7, you will be able to access the "bar" exception with.getSuppressed. In the case of Java 6, there will be no way to access the "bar" exception as it will have been thrown away. ** Usage To use this for a Leiningen project: [pjstadig/scopes "0.3.0"]
Or for a Maven project
:
: pjstadig :scopes :0.3.0 :A resource scope is established using the
with-resource-scopemacro, and objects are registered with the closest dynamic scope usingscoped!orscoped-thunk!. For example:: (require '[pjstadig.scopes :refer [scoped! with-resource-scope]]) : : (defn use-a-resource [f] : (line-seq (scoped! (io/input-stream (io/file f))))) : : (with-resource-scope : (use-a-resource "/etc/hosts"))
The
closeable?function can be used to determine if an object satisfies theScopedCloseableprotocol.: user=> (closeable? 1) : false ** License : Copyright © 2013, 2014 Paul Stadig and contributors. All rights reserved. : : This Source Code Form is subject to the terms of the Mozilla Public License, : v. 2.0. If a copy of the MPL was not distributed with this file, You can : obtain one at http://mozilla.org/MPL/2.0/. : : This Source Code Form is "Incompatible With Secondary Licenses", as defined : by the Mozilla Public License, v. 2.0.