-
Notifications
You must be signed in to change notification settings - Fork 614
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
New concurrency primitives #1006
Merged
mpilquist
merged 24 commits into
typelevel:series/0.10
from
SystemFw:feature/ref-noActor
Dec 4, 2017
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2a478d5
Make Set and TrySet symmetric
SystemFw 7702063
Probably broken attempt at non actor Ref
SystemFw 0b29139
Ref.modify now works, in isolation
SystemFw cb2f37d
Add race
SystemFw 1972ce7
Tests passing on Actor-less Ref
SystemFw aebbeda
Cleanup Ref implementation
SystemFw 317625c
Add rudimentary, ballpark benchmark
SystemFw 88f1936
Add Promise
SystemFw 6efc291
Add `access` to SyncRef
SystemFw bda5ece
Port async structures to SyncRef
SystemFw 26515e4
Add ballpark benchmark to Promise
SystemFw a6c6743
Discuss Promise design choices
SystemFw 6a7972d
Move to Promise
SystemFw 5eefcc1
General cleanup of the `async` package
SystemFw 9983005
Move Effect constraint and EC to Promise constructor
SystemFw a2489d9
Give Promise set-once semantics
SystemFw 7f6a305
Replace MsgId with Token
SystemFw af5f4c4
Remove unnecessary `fork(setSync)`
SystemFw 6d5f172
Add tests for Promise and Ref
SystemFw bb5c5e0
Update contributors
SystemFw 9224c27
Enforce set-once semantics for Promise
SystemFw 430ba56
Add scaladoc for Ref
SystemFw 709d120
Add scaladoc to Promise
SystemFw 64ae893
Minor rewording
SystemFw 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 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 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 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 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 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,49 @@ | ||
package fs2 | ||
package async | ||
|
||
import cats.effect.IO | ||
import cats.implicits._ | ||
|
||
class RefSpec extends Fs2Spec with EventuallySupport { | ||
|
||
"Ref" - { | ||
|
||
"concurrent modifications" in { | ||
val finalValue = 10 | ||
// Cannot use streams, parallelSequence or Promise since they are implemented with Ref | ||
val r = refOf[IO, Int](0).unsafeRunSync | ||
|
||
List.fill(finalValue) { | ||
fork(r.modify(_ + 1)) | ||
}.sequence.unsafeRunSync | ||
|
||
eventually { r.get.unsafeRunSync shouldBe finalValue } | ||
} | ||
|
||
"successful access" in { | ||
val op = for { | ||
r <- refOf[IO, Int](0) | ||
valueAndSetter <- r.access | ||
(value, setter) = valueAndSetter | ||
success <- setter(value + 1) | ||
result <- r.get | ||
} yield success && result == 1 | ||
|
||
op.unsafeRunSync shouldBe true | ||
} | ||
|
||
"failed access" in { | ||
val op = for { | ||
r <- refOf[IO, Int](0) | ||
valueAndSetter <- r.access | ||
(value, setter) = valueAndSetter | ||
_ <- r.setSync(5) | ||
success <- setter(value + 1) | ||
result <- r.get | ||
} yield !success && result == 5 | ||
|
||
op.unsafeRunSync shouldBe true | ||
} | ||
|
||
} | ||
} |
This file contains 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 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 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 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 was deleted.
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.
could we get rid of
x
?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.
Yes. I left it there because I already have code to make this function simpler, exploiting the fact that
set
will fail on second set (and that needs thex
)