Skip to content

feat(pool): port runtime-agnostic object pools - #177

Merged
tisonkun merged 2 commits into
mainfrom
codex/port-fastpool
Aug 23, 2026
Merged

tisonkun merged 2 commits into
mainfrom
codex/port-fastpool

Conversation

@tisonkun

@tisonkun tisonkun commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add an opt-in pool feature backed by Asyncband's semaphore
  • port Fastpool's bounded and unbounded pools, manager lifecycle, retention, status, and cancellation behavior
  • keep timeouts, maintenance tasks, task spawning, and scheduling outside the pool so callers can compose their runtime of choice
  • keep the pool feature free of third-party normal dependencies
  • provisionally classify pools as "resource reuse" and broaden the project wording from synchronization primitives to synchronization and coordination tools
  • port the cancellation and replenish regression tests and extend public trait assertions

The code is ported from Fastpool v1.1.1 (e4c65f1).

Why this is a draft

This is a concrete prototype for #176, not a final decision that object pools belong in the main crate. It chooses the main-crate feature shape so we can review the real API, dependency, documentation, and project-positioning consequences.

The provisional boundary demonstrated here is: Asyncband may own runtime-agnostic reusable-resource lifecycle and synchronization, but it does not own clocks, runtime integration, task spawning, or scheduling.

Proposed API shape

asyncband = { version = "0.7", features = ["pool"] }
use asyncband::pool::ManageObject;
use asyncband::pool::bounded;
use asyncband::pool::unbounded;

The feature is defined as pool = ["semaphore"]. Bounded pools use Asyncband's owned semaphore permits; both pool variants use the shared ManageObject, ObjectStatus, queue strategy, cancellation strategy, and retain result types.

Bounded-pool user accounting uses a small private guard. It rolls the count back when get() fails or is cancelled, and is intended to be replaced by the standard library's DropGuard if that API stabilizes.

Timeouts remain caller-side composition:

let object = tokio::time::timeout(deadline, pool.get()).await??;

Review questions

  1. Is "runtime-agnostic synchronization and coordination tools" a useful long-term boundary, or is the current synchronization-primitive framing more coherent?
  2. If pools fit the project, should they live behind a main-crate feature or in a sibling crate?
  3. Is asyncband::pool::{bounded, unbounded} the right namespace and API surface?
  4. Should a final port preserve the full Fastpool surface, or start with a smaller bounded-pool API?

Validation

  • cargo x lint
  • cargo x check
  • cargo x test --no-capture
  • cargo tree -p asyncband --no-default-features --features pool -e normal
  • cargo publish --package asyncband --locked --dry-run

Refs #176

@tisonkun
tisonkun marked this pull request as ready for review August 23, 2026 16:36
@tisonkun

Copy link
Copy Markdown
Member Author

I'll merge this patch now and see if we will have a good shape of object pools in asyncband. We can always revert (remove) this function later.

@tisonkun
tisonkun merged commit 9d2dfc7 into main Aug 23, 2026
9 checks passed
@tisonkun
tisonkun deleted the codex/port-fastpool branch August 23, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant