Parts: resources an addon owns that can be released while the addon stays mounted, and reopened on the next use.
A part is opened by its first acquire!, touched by every use, and closed by
a sweep once it has been idle for its :idle-ms with nothing using it. Closing
releases the resource (a cache, an index, a connection pool, a model); the
part itself stays registered and opens again when next acquired.
(def index (part/part {:id :carto/index :idle-ms 600000 :open (fn [] (load-index)) :close (fn [idx] (release idx))})) (part/register-part! "hive.carto" index) (part/with-part [idx index] (query idx q))
Closing never deletes data: :close releases what :open acquired.
Parts: resources an addon owns that can be released while the addon stays
mounted, and reopened on the next use.
A part is opened by its first `acquire!`, touched by every use, and closed by
a sweep once it has been idle for its :idle-ms with nothing using it. Closing
releases the resource (a cache, an index, a connection pool, a model); the
part itself stays registered and opens again when next acquired.
(def index (part/part {:id :carto/index :idle-ms 600000
:open (fn [] (load-index))
:close (fn [idx] (release idx))}))
(part/register-part! "hive.carto" index)
(part/with-part [idx index] (query idx q))
Closing never deletes data: :close releases what :open acquired.(acquire! p)The part's resource, opening it first when closed. Touches the part. Throws what :open throws; the part stays closed in that case.
The part's resource, opening it first when closed. Touches the part. Throws what :open throws; the part stays closed in that case.
(begin-use! p)Acquire P and count one use in flight. Pair with end-use!.
Acquire P and count one use in flight. Pair with end-use!.
(close! p)Close P now unless a use is in flight. Returns :closed, :already-closed or :in-flight. A :close that throws is recorded; the part still counts as closed.
Close P now unless a use is in flight. Returns :closed, :already-closed or :in-flight. A :close that throws is recorded; the part still counts as closed.
(close-owner! owner)Close every part of OWNER and forget them. Returns the ids closed now.
Close every part of OWNER and forget them. Returns the ids closed now.
(idle? p now)True when P is open, unused, and untouched for its :idle-ms as of NOW.
True when P is open, unused, and untouched for its :idle-ms as of NOW.
(part {:keys [id idle-ms open close clock]})A closed part. OPTS: :id keyword, unique within its owner :idle-ms idle time before a sweep may close it :open (fn [] resource) :close (fn [resource]), optional :clock (fn [] ms), optional, for tests
A closed part. OPTS: :id keyword, unique within its owner :idle-ms idle time before a sweep may close it :open (fn [] resource) :close (fn [resource]), optional :clock (fn [] ms), optional, for tests
(parts-of owner){part-id Part} registered under OWNER.
{part-id Part} registered under OWNER.
(register-part! owner p)Register P under OWNER (an addon id). A part already registered under the same id is closed and replaced. Returns P.
Register P under OWNER (an addon id). A part already registered under the same id is closed and replaced. Returns P.
(reset-registry!)Close and forget every part. For tests.
Close and forget every part. For tests.
(sweep! now)Close every idle part as of NOW. Returns {owner [part-id ...]} for the parts closed.
Close every idle part as of NOW. Returns {owner [part-id ...]} for the parts
closed.(with-part [sym p] & body)Bind SYM to P's resource for BODY, holding P open for its duration.
Bind SYM to P's resource for BODY, holding P open for its duration.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |