Coder Social home page Coder Social logo

piotr-yuxuan / closeable-map Goto Github PK

View Code? Open in Web Editor NEW
56.0 56.0 2.0 5.68 MB

Application state management made simple: a Clojure map that implements java.io.Closeable.

Home Page: https://github.com/piotr-yuxuan/closeable-map

License: European Union Public License 1.2

Clojure 100.00%
clojure clojure-maps closeable component integrant map mount state state-management system with-open

closeable-map's Introduction

See my ๐Ÿ”— portfolio.

[:html {}
  [:body {}
    [:h1.fancy#greetings "Hello, world! ๐ŸŒ…"]
    [:script #(println "Yay ๐ŸŽ‰")]]]

closeable-map's People

Contributors

piotr-yuxuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

closeable-map's Issues

Request for comments: `java.io.{Throwable,Error,Exception}`, `clojure.lang.ExceptionInfo`?

Currently closeable-map tries very hard to swallow everything, and as such uses the apex class java.io.Throwable in order to make completely sure errors truly are silent. This is opinionated. Is it a sane default? Why choose another better default? Perhaps this behaviour could be dynamically tuned according to the user's whishes?

Example:

This kind of change would break the API as a matter of course, and would trigger version 1.0.0.

Jar issue

Looks like something is wrong with the uploaded jar.

suggested readme example

here is a suggestion for your TL;DR example

TL;DR example

;; in your project
(require '[piotr-yuxuan/closeable-map :refer [closeable-map]])

(defn start
  "Return a running context with values that can be closed."
  [config]
  (closeable-map
    {;; Kafka producers/consumers are java.io.Closeable
     :producer (kafka-producer config)
     :consumer (kafka-consumer config)

     ;; File streams are java.io.Closeable too
     :outfile (io/output-stream (io/file "/tmp/outfile.txt"))

     ;; some libs return a function which when called stop the server, like:
     :server ^closeable-map/fn (http/start-server (api config) (:server config))}))


;; then you can start/stop the app in the repl with:
(comment
  (def config (load-config))
  (def system (start config))

  ;; stop/close all processes/resources with
  (.close system)
)


;; or use in conjunction with `with-open` like in test file
(with-open [context (start config)]
  (testing "unit test with isolated, repeatable context"
    (is (= :yay/๐Ÿš€ (some-business/function context)))))

When (.close system) is executed, it will:

  • Recursively close all instances of java.io.Closeable and java.lang.AutoCloseable
  • Recursively call all stop functions marked with ^:closeable-map/fn
  • Skip all Closeable marked with ^:closeable-map/ignore
  • If the key :closeable-map/on-close is present, it will be assumed
    as a function which takes one argument (the map itself) and used
    run additional closing logic.
    (closeable-map
      {;; Kafka producers/consumers are java.io.Closeable
       :producer (kafka-producer config)
       :consumer (kafka-consumer config)
    
       ;; this function will be executed before the auto close.
       :closeable-map/on-close (fn [this-map] (flush!))
       }
    )

add the possibility to ignore closing errors during close

It would be good to be able to ignore errors during close at key level or for the whole map, like

(closeable-map
    ^:closeable-map/ignore-errors
    {;; Kafka producers/consumers are java.io.Closeable
     :producer (kafka-producer config)
     :consumer (kafka-consumer config)

     ;; File streams are java.io.Closeable too
     :outfile (io/output-stream (io/file "/tmp/outfile.txt"))

     ;; some libs return a function which when called stop the server, like:
     :server ^closeable-map/fn (http/start-server (api config) (:server config))})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.