-
Couldn't load subscription status.
- Fork 1.4k
[9390] - add tryAcquire to Semaphore #9825
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
[9390] - add tryAcquire to Semaphore #9825
Conversation
|
@hearnadam Hi, I have closed previous approved PR #9600 and opened this one instead. |
| * releasing them after execution. Returns `None` if no permits were | ||
| * available. | ||
| */ | ||
| def tryWithPermit[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = |
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.
| def tryWithPermit[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = | |
| final def tryWithPermit[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = |
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.
@hearnadam TSemaphore is a final class, hence all member of the class are effectively final by default. that is why final modifier is redundant
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.
| final class TSemaphore private (val permits: TRef[Long]) extends Serializable { |
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.
Ah right, thanks
| * releasing them after execution. Returns `None` if no permits were | ||
| * available. | ||
| */ | ||
| def tryWithPermits[R, E, A](n: Long)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = |
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.
| def tryWithPermits[R, E, A](n: Long)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = | |
| final def tryWithPermits[R, E, A](n: Long)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, Option[A]] = |
| * Tries to acquire the specified number of permits in a transactional | ||
| * context. Returns `true` if the permits were acquired, otherwise `false`. | ||
| */ | ||
| def tryAcquireN(n: Long): USTM[Boolean] = |
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.
| def tryAcquireN(n: Long): USTM[Boolean] = | |
| final def tryAcquireN(n: Long): USTM[Boolean] = |
| * Tries to acquire a single permit in a transactional context. Returns `true` | ||
| * if the permit was acquired, otherwise `false`. | ||
| */ | ||
| def tryAcquire: USTM[Boolean] = tryAcquireN(1L) |
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.
| def tryAcquire: USTM[Boolean] = tryAcquireN(1L) | |
| final def tryAcquire: USTM[Boolean] = tryAcquireN(1L) |
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.
Thank you!
Added tryAcquire to Semaphore and TSemaphore as per Issue #9390