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

Queue new API + docs #30

Merged
merged 38 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dbcdf4a
Merge new Queue internal impl with Queue
nomisRev Feb 19, 2020
af71858
Add some additional tests for new behavior
nomisRev Feb 19, 2020
4f83932
Add more tests
nomisRev Feb 20, 2020
2d2f695
Merge remote-tracking branch 'origin/master' into sv-queue-part-2
nomisRev Feb 20, 2020
d32ec2d
Add Concurrent syntax for Queue
nomisRev Feb 20, 2020
0e489f8
Fix compileJmhKotlin
nomisRev Feb 20, 2020
e98dc30
Merge branch 'master' into sv-queue-part-2
nomisRev Feb 21, 2020
e34098b
Fix documentation
nomisRev Feb 21, 2020
ecd4eec
Merge branch 'master' into sv-queue-part-2
rachelcarmena Feb 25, 2020
f3ea469
Merge branch 'master' into sv-queue-part-2
nomisRev Feb 26, 2020
73efd48
Merge remote-tracking branch 'origin/master' into sv-queue-part-2
nomisRev Mar 6, 2020
fa0f32a
Update Queue tests
nomisRev Mar 7, 2020
34ef6f3
Merge branch 'master' into sv-queue-part-2
nomisRev Mar 7, 2020
701ea3f
Add takeAll & peekAll
nomisRev Mar 8, 2020
b777802
Add tryOfferAll
nomisRev Mar 9, 2020
c48514d
Add offerAll
nomisRev Mar 9, 2020
a53876d
First round of PR review
nomisRev Mar 10, 2020
76e6fc4
Merge remote-tracking branch 'origin/master' into sv-queue-part-2
nomisRev Mar 10, 2020
d9b29ba
Merge branch 'master' into sv-queue-part-2
nomisRev Mar 10, 2020
2b903c2
Apply suggestions from doc lang review
nomisRev Mar 10, 2020
77abcc1
Fix offerAll cancelation
nomisRev Mar 10, 2020
75861ec
Merge branch 'master' into sv-queue-part-2
aballano Mar 10, 2020
98f339f
Add docs to Dequeue
nomisRev Mar 11, 2020
ee3faf7
Merge branch 'sv-queue-part-2' of github.com:arrow-kt/arrow-fx into s…
nomisRev Mar 11, 2020
7b2df23
Remove `shutdown` from `Queue` API
nomisRev Mar 11, 2020
58d9eef
Remove LinkedMap and use LinkedHashMap instead
nomisRev Mar 11, 2020
a8ab3e2
Refactor API to be Iterable instead of Collection
nomisRev Mar 11, 2020
cdd4a7f
Add tests to check all strategies
nomisRev Mar 11, 2020
40657f3
Add examples queue strategies
nomisRev Mar 11, 2020
99217bc
Fix unresolved A Dequeue docs
nomisRev Mar 11, 2020
61e7155
Fix Dequeue docs some more
nomisRev Mar 11, 2020
a200d41
Fix Sliding KDoc example
nomisRev Mar 11, 2020
aa69fbe
Merge branch 'master' into sv-queue-part-2
aballano Mar 13, 2020
2aa7ddf
Merge branch 'master' into sv-queue-part-2
danimontoya Mar 13, 2020
ae81131
Merge branch 'master' into sv-queue-part-2
aballano Mar 16, 2020
9e6c6c7
Apply suggestions from doc review
nomisRev Mar 17, 2020
ff076bd
Code review, remove Shutdown references
nomisRev Mar 17, 2020
ee1e753
Merge branch 'sv-queue-part-2' of github.com:arrow-kt/arrow-fx into s…
nomisRev Mar 17, 2020
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
9 changes: 1 addition & 8 deletions arrow-benchmarks-fx/src/jmh/kotlin/arrow/benchmarks/Queue.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package arrow.benchmarks

import arrow.fx.ConcurrentQueue
import arrow.fx.ForIO
import arrow.fx.IO
import arrow.fx.IOOf
Expand All @@ -9,7 +8,6 @@ import arrow.fx.extensions.io.concurrent.concurrent
import arrow.fx.extensions.io.functor.unit
import arrow.fx.extensions.io.monad.flatMap
import arrow.fx.fix
import arrow.fx.internal.CancellableQueue
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.CompilerControl
import org.openjdk.jmh.annotations.Fork
Expand All @@ -34,12 +32,10 @@ open class Queue {
var size: Int = 0

var ConcurQueue by Delegates.notNull<Queue<ForIO, Int>>()
var CancelQueue by Delegates.notNull<Queue<ForIO, Int>>()

@Setup(Level.Trial)
fun createQueues(): Unit {
ConcurQueue = ConcurrentQueue.empty<ForIO, Int>(IO.concurrent()).fix().unsafeRunSync()
CancelQueue = CancellableQueue.empty<ForIO, Int>(IO.concurrent()).fix().unsafeRunSync()
ConcurQueue = Queue.unbounded<ForIO, Int>(IO.concurrent()).fix().unsafeRunSync()
}

fun <A> IOOf<A>.repeat(n: Int): IO<A> =
Expand All @@ -52,7 +48,4 @@ open class Queue {

@Benchmark
fun concurrentQueue(): Unit = loop(ConcurQueue)

@Benchmark
fun cancellableQueue(): Unit = loop(CancelQueue)
}
49 changes: 0 additions & 49 deletions arrow-docs/docs/queue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,52 +162,3 @@ fun main(args: Array<String>) {
println(result.unsafeRunSync())
}
```

### Shutting down

A `Queue` also has the ability to be `shutdown`, interrupting any future calls to `take` or `offer` with a
`QueueShutdown` error and cancelling any suspended fibers waiting to `take` or `offer`.

```kotlin:ank:playground
import arrow.fx.*
import arrow.fx.extensions.fx
import arrow.fx.extensions.io.concurrent.concurrent

fun main(args: Array<String>) {
val result =
//sampleStart
IO.fx {
val q = !Queue.bounded<ForIO, Int>(10, IO.concurrent())
val t = !q.take().fork()
!q.shutdown()
!t.join() // Attempting to `join` after `shutdown` results in a `QueueShutdown` error
}
//sampleEnd
println(result.attempt().unsafeRunSync())
}
```

Consumers of the `Queue` can also track the event of a shutdown by calling `awaitShutdown` to receive a suspended
`Concurrent<F>` that will resume once the `Queue` has been shutdown.

```kotlin:ank:playground
import arrow.fx.*
import arrow.fx.extensions.fx
import arrow.fx.extensions.io.concurrent.concurrent

fun main(args: Array<String>) {
val result =
//sampleStart
IO.fx {
val q = !Queue.bounded<ForIO, Int>(10, IO.concurrent())
val onShutdown = !q.awaitShutdown().fork()
!q.offer(42)
val fortyTwo = !q.take()
!q.shutdown()
!onShutdown.join()
fortyTwo
}
//sampleEnd
println(result.unsafeRunSync())
}
```
20 changes: 20 additions & 0 deletions arrow-fx-test/src/main/kotlin/arrow/fx/test/laws/Law.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package arrow.fx.test.laws

import arrow.core.extensions.either.eq.eq
import arrow.fx.IO
import arrow.fx.IOOf
import arrow.fx.fix
import arrow.fx.extensions.io.applicative.applicative
import arrow.fx.extensions.io.concurrent.waitFor
import arrow.fx.typeclasses.Duration
import arrow.fx.typeclasses.seconds
import arrow.core.test.generators.tuple2
import arrow.core.test.generators.tuple3
import arrow.core.test.generators.tuple4
Expand All @@ -14,6 +22,18 @@ import io.kotlintest.shouldNot
fun <A> A.equalUnderTheLaw(b: A, eq: Eq<A>): Boolean =
shouldBeEq(b, eq).let { true }

fun <A> IOOf<A>.equalUnderTheLaw(b: IOOf<A>, EQA: Eq<A> = Eq.any(), timeout: Duration = 5.seconds): Boolean =
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this explicit equalUnderTheLaw? Cannot we test like before using the one above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's for a proper assertion message. The one implement through IO.toString is not very meaningful.

#30 (comment)

(this should object : Matcher<IOOf<A>> {
override fun test(value: IOOf<A>): Result =
arrow.core.Either.eq(Eq.any(), EQA).run {
IO.applicative().mapN(value.fix().attempt(), b.fix().attempt()) { (a, b) ->
Result(a.eqv(b), "Expected: $b but found: $a", "$b and $a should be equal")
}
.waitFor(timeout)
.unsafeRunSync()
}
}).let { true }

fun <A> A.shouldBeEq(b: A, eq: Eq<A>): Unit = this should matchUnderEq(eq, b)

fun <A> A.shouldNotBeEq(b: A, eq: Eq<A>): Unit = this shouldNot matchUnderEq(eq, b)
Expand Down
219 changes: 0 additions & 219 deletions arrow-fx/src/main/kotlin/arrow/fx/ConcurrentQueue.kt

This file was deleted.

Loading