pub struct Pool { /* private fields */ }Expand description
A multi-station connection pool — see this module’s own doc for the full design.
links is a plain append-only Vec<Arc<PooledLink>> behind an async
RwLock, deliberately NOT a HashMap/HashSet — this is the one
change made in direct response to the SAME class of bug found (twice,
independently) porting this feature to macula-go (map[string]*link
randomizing iteration order) and macula-dotnet (migrating to
ConcurrentDictionary for concurrent-add safety silently broke
FirstSuccess’s reliance on insertion order). A Vec, appended to
under the same lock that’s ALSO taken to read it, has no separate
enumeration-order concept to accidentally break — insertion order IS
the order, by construction, with nothing to track alongside it the way
go’s fix (tracking iteration order separately) or dotnet’s fix (an
explicit Ordinal field) both had to.
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn connect(
seeds: Vec<Seed>,
trust: Trust,
identity: KeyPair,
options: PoolOptions,
) -> Arc<Pool> ⓘ
pub fn connect( seeds: Vec<Seed>, trust: Trust, identity: KeyPair, options: PoolOptions, ) -> Arc<Pool> ⓘ
Spawn a pool with one link per seed. Returns as soon as every link’s dial has STARTED, not once any is connected — handshakes complete asynchronously, matching macula_client:connect/2 and every other port of this pool shape.
Sourcepub async fn call(
self: &Arc<Self>,
procedure: &str,
realm: [u8; 32],
payload: Value,
deadline_ms: i128,
) -> Result<CallResponse, PoolCallError>
pub async fn call( self: &Arc<Self>, procedure: &str, realm: [u8; 32], payload: Value, deadline_ms: i128, ) -> Result<CallResponse, PoolCallError>
Send a signed CALL, choosing among currently-connected links per
PoolOptions::link_selection, trying each in order until one
answers (a transport-level failure marks that link disconnected and
triggers its respawn, then moves to the next candidate — a BOLT#4
ERROR response is still a successful call as far as this pool is
concerned, exactly like a bare Session::call).
Sourcepub async fn publish(
self: &Arc<Self>,
spec: &PublishSpec,
) -> Result<(), PoolPublishError>
pub async fn publish( self: &Arc<Self>, spec: &PublishSpec, ) -> Result<(), PoolPublishError>
Send a signed PUBLISH, fanning out to up to
PoolOptions::replication_factor currently-connected links
(ordered by PoolOptions::link_selection). Partial success counts
as success, matching macula-ts/macula-dotnet’s own publish-fanout
contract.
Sourcepub async fn status(&self) -> PoolStatus
pub async fn status(&self) -> PoolStatus
Aggregate health snapshot.
Sourcepub async fn links(&self) -> Vec<LinkInfo>
pub async fn links(&self) -> Vec<LinkInfo>
Per-link snapshot, in seed-list/discovery order — see Pool’s own
doc on why a plain Vec already guarantees this without any extra
bookkeeping.
Sourcepub async fn close(&self, reason: &str, detail: Option<&str>)
pub async fn close(&self, reason: &str, detail: Option<&str>)
Sends GOODBYE on every currently-connected link and stops all
background dial/discovery tasks. Waits for every background task
(respawn lifecycles, the discovery loop) to actually be gone
BEFORE draining/closing links — see Pool’s own field doc on
tasks for why this ordering, specifically, is load-bearing.
Does not wait for the GOODBYE writes themselves to finish being
scheduled beyond Session::close’s own bounded drain.