Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Add withConcurrentVar, modify and modify_ #298

Merged
merged 6 commits into from Nov 19, 2020
Merged

Conversation

1Jajen1
Copy link
Member

@1Jajen1 1Jajen1 commented Oct 8, 2020

A few useful methods for manipulating ConcurrentVars safely using bracketCase.

A few useful methods for manipulating ConcurrentVars safely using bracketCase
Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

Should we add some tests? It's bracket composition...

Could we add some docs to explain why these methods are favored like we discussed on Slack or in the STM PR?

)

override suspend fun <B> modify(f: suspend (A) -> Tuple2<A, B>): B {
// ugly. Is there a better way?
Copy link
Member

Choose a reason for hiding this comment

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

This is the fastest and simplest implementation afaik. Just a tad ugly yes 😅

@1Jajen1
Copy link
Member Author

1Jajen1 commented Oct 8, 2020

Well it is just composition so I don't think being very exhaustive in the tests is necessary, although 1-2 basic tests can't hurt to at least show that it works.

I'll add something to docs, although this is best explained in the context of how to use ConcurrentVar in general. As in "Hey you want to use ConcurrentVar as a Lock? Here are some helpers that make sure you don't screw up with exceptions or cancellation".

@nomisRev
Copy link
Member

Great tests and docs, thanks @1Jajen1!

@nomisRev nomisRev requested a review from a team October 13, 2020 07:15
@1Jajen1 1Jajen1 requested review from a team and removed request for a team November 17, 2020 19:05
Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

Looks great, thanks Jannis,

when (exit) {
is ExitCase.Failure -> put(a)
is ExitCase.Cancelled -> put(a)
is ExitCase.Completed -> put(res!!)
Copy link
Member

Choose a reason for hiding this comment

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

res?.let(::put) maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should put(res!!) ever fail for some reason I'd rather have it crash than not put back the value because that could lead to a very confusing deadlock.

@1Jajen1 1Jajen1 merged commit 01c3474 into master Nov 19, 2020
@1Jajen1 1Jajen1 deleted the jo-concVar-extras branch November 19, 2020 13:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants