how do we access Java collection APIs like `Queue`...
# multiplatform
a
how do we access Java collection APIs like
Queue
in Kotlin Multiplatform?
e
you can't
a
So for collections like a Queue, what would be the alternative to use in KMP?
i
e
java.util.Queue is not quite the same as kotlin.collections.ArrayQueue: the former has non-blocking offer/poll methods
if you're not using that, only the blocking methods of an unbounded java.util.ArrayDeque, then sure, kotlin.collections.ArrayQueue can give you the same functionality
c
If you want to use a Queue to send objects across threads (blocking queue of requests), the multiplatform equivalent would be KotlinX coroutines' Channel
👍 2
i
@ephemient In what sense offer/poll are non-blocking?
Queue.offer
method docs only mention the behavior regarding capacity-restricted queues. For unbounded queues
offer
should be equivalent to
add
. And for
poll
there's a direct equivalent in `ArrayDeque`:
removeFirstOrNull