An experimental Racket library providing an abstraction for values associated with external resources that allows automatic resource pooling, per-thread virtual construction, and monadic composition
Given a disposable value, it should be possible to create a virtual value - a thunk that when called returns a thread-specific instance of the disposable that is automatically deallocated when the calling thread dies. Combined with #1, this should make it possible to generalize the very nice behavior of the db library's virtual connections backed by connection pools. The pattern would be as follows:
Define a disposable representing the connection
Define a pooled disposable wrapping the connection disposable
Globally provide the pooled disposable, using a plumber to deallocate the pool on shutdown (note that pooled disposables are double-wrapped, the outer disposable represents the lifetime of the pool while the inner disposable represents the lifetime of a lease of a pooled value)
Virtually provide a wrapper around the pool's lease disposable
Voila! After step 4, there should be a thunk that implements the behavior of virtual-connection for an arbitrary disposable. Calling the thunk returns a thread-specific instance of the disposable value without needing with-disposable, and after the thread dies the thread-specific instance is returned to the global disposable pool. At program shutdown, all disposables in the pool are deallocated.
Given a disposable value, it should be possible to create a virtual value - a thunk that when called returns a thread-specific instance of the disposable that is automatically deallocated when the calling thread dies. Combined with #1, this should make it possible to generalize the very nice behavior of the
db
library's virtual connections backed by connection pools. The pattern would be as follows:Voila! After step 4, there should be a thunk that implements the behavior of
virtual-connection
for an arbitrary disposable. Calling the thunk returns a thread-specific instance of the disposable value without needingwith-disposable
, and after the thread dies the thread-specific instance is returned to the global disposable pool. At program shutdown, all disposables in the pool are deallocated.