On this page:
Disposable Values
8.12

Disposable Values🔗ℹ

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:

    1 Basic Disposable API and Concepts

      1.1 Data Definition

      1.2 Consuming Disposable Values

      1.3 Unsafe Allocation of Disposables

      1.4 Monadic Composition of Disposables

      1.5 Asynchronous Cleanup

      1.6 Disposables with Associated Custodians

      1.7 Memoization and Disposables

    2 Reusing Disposables with Pools

      2.1 Global Pools with Virtual Leases

    3 Transient Values

      3.1 Definition and Construction

      3.2 Manipulating Transients

    4 Batteries-Included Disposables

      4.1 Filesystem Disposables

      4.2 Utilities for Testing Disposables

      4.3 Example Disposables