-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add documentation #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
satorg
wants to merge
6
commits into
typelevel:main
Choose a base branch
from
satorg:add-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add documentation #643
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,17 @@ import scala.concurrent.duration._ | |
| * This pools internal guarantees are that the max number of values are in the pool at any time, not | ||
| * maximum number of operations. To do the latter application level bounds should be used. | ||
| * | ||
| * A background reaper thread is kept alive for the length of the pools life. | ||
| * A background reaper thread is kept alive for the length of the pool's life. | ||
| * | ||
| * When resources are taken from the pool they are received as a [[Managed]]. This [[Managed]] has a | ||
| * Ref to a [[Reusable]] which indicates whether or not the pool can reuse the resource. | ||
| * `Ref` to a [[Reusable]] which indicates whether the pool can reuse the resource. | ||
| * | ||
| * `Pool` is a convenience, single-key specialization of [[KeyPool]] that does not partition | ||
| * resources by key and exposes simpler `take`/`state` APIs. | ||
| * | ||
| * @see | ||
| * [[KeyPool]] | ||
| */ | ||
|
|
||
| trait Pool[F[_], B] { | ||
|
|
||
| /** | ||
|
|
@@ -100,32 +105,100 @@ object Pool { | |
| onReaperException | ||
| ) | ||
|
|
||
| /** | ||
| * Register a callback `f` to run after a new [[Managed]] item is created. Any error raised by | ||
| * the callback is ignored, and the created item is returned unchanged. | ||
| * | ||
| * @note | ||
| * If multiple callbacks are registered, their execution order is not guaranteed and callers | ||
| * should not rely on any particular ordering. | ||
| */ | ||
| def doOnCreate(f: B => F[Unit]): Builder[F, B] = | ||
| copy(kpRes = this.kpRes.flatMap(v => Resource.eval(f(v).attempt.void.as(v)))) | ||
|
|
||
| /** | ||
| * Register a callback `f` to run when a [[Managed]] item is about to be destroyed. Any error | ||
| * raised by the callback is ignored, and the item will be destroyed regardless. | ||
| * | ||
| * @note | ||
| * If multiple callbacks are registered, their execution order is not guaranteed and callers | ||
| * should not rely on any particular ordering. | ||
| */ | ||
| def doOnDestroy(f: B => F[Unit]): Builder[F, B] = | ||
| copy(kpRes = | ||
| this.kpRes.flatMap(v => Resource.make(Applicative[F].unit)(_ => f(v).attempt.void).as(v)) | ||
| ) | ||
|
|
||
| /** | ||
| * Set the default [[Reusable]] state applied when resources are returned to the pool. This | ||
| * default can be overridden per-resource via [[Managed.canBeReused]] from [[Pool.take]]. If not | ||
| * configured, the default is [[Reusable.Reuse]]. | ||
| * | ||
| * @param defaultReuseState | ||
| * whether resources returned to the pool should be reused ([[Reusable.Reuse]]) or destroyed | ||
| * ([[Reusable.DontReuse]]) by default. | ||
| */ | ||
| def withDefaultReuseState(defaultReuseState: Reusable): Builder[F, B] = | ||
| copy(kpDefaultReuseState = defaultReuseState) | ||
|
|
||
| /** | ||
| * Set how long an idle resource is allowed to remain in the pool before it becomes eligible for | ||
| * eviction. If not configured, the builder defaults to 30 seconds. | ||
| * | ||
| * @param duration | ||
| * maximum idle time allowed in the pool. | ||
| */ | ||
| def withIdleTimeAllowedInPool(duration: Duration): Builder[F, B] = | ||
| copy(idleTimeAllowedInPool = duration) | ||
|
|
||
| /** | ||
| * Set the interval between eviction runs of the pool reaper. If not configured, the builder | ||
| * defaults to 5 seconds. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + |
||
| * | ||
| * @param duration | ||
| * time between successive eviction runs. | ||
| */ | ||
| def withDurationBetweenEvictionRuns(duration: Duration): Builder[F, B] = | ||
| copy(durationBetweenEvictionRuns = duration) | ||
|
|
||
| /** | ||
| * Set the maximum number of idle resources allowed across the pool. If not configured, the | ||
| * builder defaults to 100. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + |
||
| * | ||
| * @param maxIdle | ||
| * maximum idle resources in the pool. | ||
| */ | ||
| def withMaxIdle(maxIdle: Int): Builder[F, B] = | ||
| copy(kpMaxIdle = maxIdle) | ||
|
|
||
| /** | ||
| * Set the maximum total number of concurrent resources permitted by the pool. If not | ||
| * configured, the builder defaults to 100. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. + |
||
| * | ||
| * @param total | ||
| * maximum total resources. | ||
| */ | ||
| def withMaxTotal(total: Int): Builder[F, B] = | ||
| copy(kpMaxTotal = total) | ||
|
|
||
| /** | ||
| * Set the [[Fairness]] policy for acquiring permits from the global semaphore controlling total | ||
| * resources. If not configured, the builder defaults to [[Fairness.Fifo]]. | ||
| * | ||
| * @param fairness | ||
| * fairness policy - [[Fairness.Fifo]] or [[Fairness.Lifo]]. | ||
| */ | ||
| def withFairness(fairness: Fairness): Builder[F, B] = | ||
| copy(fairness = fairness) | ||
|
|
||
| /** | ||
| * Register a handler `f` invoked for any `Throwable` observed by the background reaper; it runs | ||
| * when the reaper loop reports an error. | ||
| * | ||
| * The provided function is invoked with any `Throwable` observed in the reaper loop. If the | ||
| * handler itself fails, that failure is swallowed and thereby ignored - the reaper will | ||
| * continue running and may invoke the handler again for subsequent errors. | ||
| */ | ||
| def withOnReaperException(f: Throwable => F[Unit]): Builder[F, B] = | ||
| copy(onReaperException = f) | ||
|
|
||
|
|
@@ -142,6 +215,14 @@ object Pool { | |
| onReaperException = onReaperException | ||
| ) | ||
|
|
||
| /** | ||
| * Create a `Pool` wrapped in a `Resource`, initializing pool internals from the configured | ||
| * builder parameters and defaults. | ||
| * | ||
| * @note | ||
| * The implementation is a thin single-key specialization that delegates to | ||
| * [[KeyPool.Builder]] under the hood. | ||
| */ | ||
| def build: Resource[F, Pool[F, B]] = { | ||
| toKeyPoolBuilder.build.map { inner => | ||
| new Pool[F, B] { | ||
|
|
@@ -153,6 +234,11 @@ object Pool { | |
| } | ||
|
|
||
| object Builder { | ||
|
|
||
| /** | ||
| * Create a new `Builder` for a `Pool` from a `Resource` that produces values stored in the | ||
| * pool. | ||
| */ | ||
| def apply[F[_]: Temporal, B]( | ||
| res: Resource[F, B] | ||
| ): Builder[F, B] = new Builder[F, B]( | ||
|
|
@@ -166,6 +252,10 @@ object Pool { | |
| Defaults.onReaperException[F] | ||
| ) | ||
|
|
||
| /** | ||
| * Convenience constructor that accepts `create` and `destroy` functions and builds a `Resource` | ||
| * internally. | ||
| */ | ||
| def apply[F[_]: Temporal, B]( | ||
| create: F[B], | ||
| destroy: B => F[Unit] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| laika.navigationOrder = [ | ||
| pool.md | ||
| keypool.md | ||
| misc.md | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| laika.targetFormats = [] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+