Thread
#multiplatform
    a

    Alberto

    1 year ago
    how do we access Java collection APIs like
    Queue
    in Kotlin Multiplatform?
    e

    ephemient

    1 year ago
    you can't
    a

    Alberto

    1 year ago
    So for collections like a Queue, what would be the alternative to use in KMP?
    e

    ephemient

    1 year ago
    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

    1 year ago
    If you want to use a Queue to send objects across threads (blocking queue of requests), the multiplatform equivalent would be KotlinX coroutines' Channel
    ilya.gorbunov

    ilya.gorbunov

    1 year ago
    @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