Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@IgorDorokhov
Copy link
Contributor

Added tryAcquire to Semaphore and TSemaphore as per Issue #9390

@IgorDorokhov
Copy link
Contributor Author

@hearnadam Hi, I have closed previous approved PR #9600 and opened this one instead.
This PR has the same exact changes as previous one. The previous PR had commits made from my another account (default one. I changed laptop without setting git username and email) which is not CLA signed.
Instead of doing rebase I decided to open a new PR

* 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]] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]] =

Copy link
Contributor Author

@IgorDorokhov IgorDorokhov Apr 26, 2025

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

Copy link
Contributor Author

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 {

Copy link
Collaborator

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]] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def tryAcquire: USTM[Boolean] = tryAcquireN(1L)
final def tryAcquire: USTM[Boolean] = tryAcquireN(1L)

Copy link
Contributor

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kyri-petrou kyri-petrou merged commit 9995327 into zio:series/2.x Apr 28, 2025
18 checks passed
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.

3 participants