interface ~~Dequeue~~<F, A>
Deprecated: The IO datatype and it’s related type classes will disappear in Arrow 0.13.0. All useful operations are offered directly over suspend functions by Arrow Fx Coroutines. https://arrow-kt.io/docs/fx/async/
Dequeue allows peeking and taking values from a Queue, but doesn’t allow offering values to the Queue. You can use Dequeue to restrict certain functions or layers of your applications to only consume values.
import arrow.fx.*
import arrow.fx.typeclasses.*
import arrow.fx.extensions.fx
import kotlin.coroutines.EmptyCoroutineContext
//sampleStart
suspend fun main(args: Array<String>): Unit = IO.fx {
fun consumeInts(e: Dequeue<ForIO, Int>, max: Int): IOOf<Unit> =
(0..max).toList().parTraverse(EmptyCoroutineContext) { i ->
IO.sleep(i * 10.milliseconds).followedBy(
e.take().effectMap { println("I took $it") }
)
}.void()
val queue = !Queue.unbounded<Int>()
!consumeInts(queue, 1000).fork()
!IO.sleep(4.seconds)
}.suspended()
//sampleEnd
See Also
peek | Peeks a value from the Queue or semantically blocks until a value becomes available. In contrast to take, peek does not remove the value from the Queue.abstract fun peek(): Kind<F, A> |
peekAll | Immediately returns all available values in the Queue, without empty’ing the Queue. It returns an emptyList when no values are available.abstract fun peekAll(): Kind<F, List <A>> |
take | Takes and removes a value from the Queue, or semantically blocks until a value becomes available.abstract fun take(): Kind<F, A> |
takeAll | Immediately returns all available values in the Queue, and empties the Queue. It returns an emptyList when no values are available.abstract fun takeAll(): Kind<F, List <A>> |
tryPeek | Tries to peek a value from the Queue. Returns immediately with either None or a value Some. In contrast to tryTake, tryPeek does not remove the value from the Queue.abstract fun tryPeek(): Kind<F, Option<A>> |
tryTake | Attempts to take a value from the Queue if one is available, this method is guaranteed not to semantically block. It returns immediately an Option with either None or a value wrapped in Some.abstract fun tryTake(): Kind<F, Option<A>> |
Queue | Lightweight Concurrent Queue for values of A.interface ~~Queue~~<F, A> : QueueOf <F, A>, Dequeue <F, A>, Enqueue <F, A> |
Do you like Arrow?
✖