Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!