Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
How to use AsyncGenerators with Kotlin/JS?

I'm currently trying to use IPFS with Kotlin/JS, though my problem isn't specific to that. The ipfs.cat() and ipfs.get() functions return an AsyncGenerator and I'm unsure how to iterate over it with Kotlin (I'm not even sure which type would best represent an AsyncIterable in kotlin)

The below code is an minimal version of what I'm trying to do, though I have not tested the code as is below. It fails with a ClassCastException since the for loop is fundamentally wrong, but I don't know what I should replace it with.

File1:

@file:JsModule("ipfs-core")
@file:JsNonModule

import kotlin.js.Promise

@JsName("create")
external fun create(config: Any = definedExternally): Promise<dynamic>

File2:

create().then { ipfs: dynamic ->
    ipfs.id().then { id: dynamic ->
        myId = id.id as String
        println(JSON.stringify(id))
    }
    val result: dynamic = ipfs.cat("bafkreihapp6racx2xf5gwnrgtsr56r37kazui3jvzzmot2nx2t6h6g2oom")
    // result is an AsyncGenerator

    // below fails with ClassCastException
    for (element: dynamic in result){
        println(element)
    }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda