alef 0.23.35

Opinionated polyglot binding generator for Rust libraries
Documentation
    @Suppress("TooGenericExceptionCaught")
    fun {{ method_name }}({{ params }}): Flow<{{ item_type }}> = callbackFlow {
        val streamHandle: Long = withContext(Dispatchers.IO) {
            {{ bridge_name }}.{{ jni_start }}(handle, mapper.writeValueAsString({{ first_param_name }}))
        }
        try {
            while (true) {
                val chunkJson: String? = withContext(Dispatchers.IO) {
                    {{ bridge_name }}.{{ jni_next }}(streamHandle)
                }
                if (chunkJson == null) break
                val chunk = mapper.readValue(chunkJson, {{ item_type }}::class.java)
                send(chunk)
            }
            close()
        } catch (e: Throwable) {
            close(e)
        }
        awaitClose {
            {{ bridge_name }}.{{ jni_free }}(streamHandle)
        }
    }