https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Alberto

06/16/2021, 11:12 PM
how do we access Java collection APIs like
Queue
in Kotlin Multiplatform?
e

ephemient

06/16/2021, 11:17 PM
you can't
a

Alberto

06/16/2021, 11:33 PM
So for collections like a Queue, what would be the alternative to use in KMP?
i
e

ephemient

06/17/2021, 2:09 AM
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

CLOVIS

06/17/2021, 11:52 AM
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

ilya.gorbunov

06/17/2021, 12:20 PM
@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