Skip to content
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

Task Ref now increments nonce with every set #749

Merged
merged 5 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions core/jvm/src/test/scala/fs2/TaskSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fs2

/**
* Created by adamchlupacek on 22/10/16.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update comment to be inline with rest of fs2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove this one all together

class TaskSpec extends Fs2Spec{

"Task" - {
"Ref" - {
"Set increments nonce" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think nonce is here internal implementation detail. What we really solving here is interleaving set and modify// access. I would prefer updated name with perhaps a short comment explaining what this tests verifies.


Task.ref[Int].flatMap{ref =>
ref.setPure(1).flatMap{_ =>
ref.access.flatMap{case ((_, set)) =>
ref.setPure(2).flatMap{_ =>
set(Right(3))
}

}
}

}.unsafeRun() shouldBe false
}
}
}
}
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/fs2/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ object Task extends TaskPlatform with TaskInstances {
else { val r = result; val id = nonce; S { cb(r.map((_,id))) } }

case Msg.Set(r) =>
nonce += 1L
if (result eq null) {
nonce += 1L
val id = nonce
waiting.values.foreach(cb => S { cb(r.map((_,id))) })
waiting = LinkedMap.empty
Expand Down