Disposable Values
(require disposable) | package: disposable |
This library defines disposables, composable first-class producers of values with associated external resources that must be allocated and deallocated such as database connections. Several safe abstractions are provided to consume disposable values while ensuring their associated resources are deallocated after use.
(define (connect!) (make-connection ...)) (define (disconnect! conn) (close-connection conn ...)) (define disposable-connection (disposable connect! disconnect!)) (with-disposable ([conn disposable-connection]) ... use conn ...)
Source code for this library is avaible on Github and is provided under the terms of the Apache License 2.0.
Warning! This library is experimental; it may change in backwards incompatible ways without notice. As such, now is the best time for feedback and suggestions so feel free to open a repository issue or reach out to me directly.
This package provides several modules, all in the disposable collection:
disposable - A safe high-level interface to disposables along with combinators for extending and composing them. Does not reprovide any of the modules listed below.
disposable/unsafe - Unsafe low-level interface for manually allocating and deallocating disposable values.
disposable/file - Disposables representing filesystem resources, such as temporary directories.
disposable/testing - Utilities for testing code that uses disposables.
disposable/example - Utilities for documenting disposables and using disposables in Scribble examples.