3 Transient Values
A transient value is a wrapper around a value allocated by a disposable that allows users of the value to have some limited control over its lifecycle. In particular, users of a transient may:
Eagerly dispose the value with transient-dispose
Replace the value with a fresh value allocated from the same disposable with transient-refresh
Directly access the value with transient-acquire, which may allocate a fresh value if the transientโs current value has already been disposed
Access the value only if it hasnโt been disposed with transient-get
Any disposable may be converted to a disposable of a transient value by using disposable-transient. Transients are intended for lightweight control of disposable allocation and deallocation in a way that cooperates with other disposable wrappers and combinators. For example, combining transients with disposable-pool allows values to be reused and allows clients to explicitly create and destroy pooled values if needed.
Transients are thread safe, but not thread isolated. A transient either contains one allocated value or contains no values, and multiple threads may call any of the above functions on transients without violating this consistency. However, the above functions will block if a new value needs to be allocated or deallocated. To acquire disposables in a thread isolated manner where each thread has unfettered access to its own private instance of a disposable, see acquire-virtual.
All of the bindings documented in this section are provided by disposable.
3.1 Definition and Construction
procedure
(transient? v) โ boolean?
v : any/c
Added in version 0.3 of package disposable.
procedure
(transient/c c) โ contract?
c : contract?
Added in version 0.3 of package disposable.
procedure
(disposable-transient disp) โ (disposable/c transient?)
disp : disposable?
> (with-disposable ([t (disposable-transient example-disposable)]) (printf "Acquired transient: ~a\n" (transient-acquire t)) (transient-refresh t) (printf "Refreshed transient: ~a\n" (transient-acquire t)))
Allocated 56
Acquired transient: 56
Deallocated 56
Allocated 64
Refreshed transient: 64
Deallocated 64
Added in version 0.3 of package disposable.
3.2 Manipulating Transients
procedure
(transient-dispose t) โ void?
t : transient?
After disposal of the value owned by t, calling transient-acquire will block on allocating a fresh value while transient-get will return #f.
> (with-disposable ([t (disposable-transient example-disposable)]) (transient-dispose t))
Allocated 82
Deallocated 82
Added in version 0.3 of package disposable.
procedure
(transient-acquire t) โ any/c
t : transient?
> (with-disposable ([t (disposable-transient example-disposable)]) (transient-dispose t) (printf "Acquired transient: ~a\n" (transient-acquire t)))
Allocated 94
Deallocated 94
Allocated 4
Acquired transient: 4
Deallocated 4
Added in version 0.3 of package disposable.
procedure
(transient-get t) โ any/c
t : transient?
> (with-disposable ([t (disposable-transient example-disposable)]) (transient-dispose t) (printf "Transient value: ~a\n" (transient-get t)))
Allocated 95
Deallocated 95
Transient value: #f
Added in version 0.3 of package disposable.
procedure
(transient-refresh t) โ any/c
t : transient?
> (with-disposable ([t (disposable-transient example-disposable)]) (printf "Refreshed value: ~a\n" (transient-refresh t)))
Allocated 23
Deallocated 23
Allocated 69
Refreshed value: 69
Deallocated 69
Added in version 0.3 of package disposable.