https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • a

    Amir Rudd

    08/13/2021, 1:24 AM
    Has anyone dealt with an issue like this before?
    * What went wrong:
    Execution failed for task ':presentation:minifyBrandProductionReleaseWithR8'.
    > Could not resolve all files for configuration ':presentation:brandProductionReleaseRuntimeClasspath'.
       > Failed to transform ktor-client-core-jvm-1.6.2.jar (io.ktor:ktor-client-core-jvm:1.6.2) to match attributes {artifactType=android-asm-instrumented-jars, asm-transformed-variant=brandProductionRelease, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
          > Execution failed for AsmClassesTransform: /root/.gradle/caches/transforms-3/0442ceba8861991962529ab9a6c53c81/transformed/jetified-ktor-client-core-jvm-1.6.2.jar.
             > Index -1 out of bounds for length 0
    a
    1 reply · 2 participants
  • m

    Muhammad Usman

    08/13/2021, 4:21 AM
    h3{+"a < b"}
    it display as it is rather then less then sign. how html entities can be displayed?
    s
    c
    5 replies · 3 participants
  • ł

    Łukasz Bednarczyk

    08/13/2021, 10:58 AM
    Does someone use something other than Exposed to communicate with a database?
    c
    m
    +1
    4 replies · 4 participants
  • j

    Jonathan Hollingsworth

    08/14/2021, 3:57 AM
    I'm using ktor, but think this might be a Gradle/IntelliJ question. I have
    kotlin("plugin.serialization") version "1.5.20"
    declared in my
    build.gradle.kts
    file, and yet I cannot use the
    *import* kotlinx.serialization.Serializable
    in my code. The "External Libraries" part of the project explorer does not show
    Gradle:io.ktor:ktor-serialization:1.6.1
    like the example code in https://ktor.io/docs/creating-http-apis.html does when I run that. I'm not sure what I need to do in order to get IntelliJ/Gradle to install the necessary dependencies so I can use them in the code?
    r
    2 replies · 2 participants
  • v

    v79

    08/14/2021, 9:35 AM
    When adding authentication to a website, do you wrap all the routes which the user must be logged into to with
    authenticate()
    or do you just add
    authenticate()
    to the routes which actually do the authentication? I'm terribly confused.
    d
    a
    7 replies · 3 participants
  • j

    Jgafner

    08/14/2021, 10:48 AM
    Hi In the app engine deployment documentation there is an error in the configuration of the artifact (point 3) : https://ktor.io/docs/google-app-engine.html#configure-app-engine-settings
    appengine {
        stage {
            artifact = "build/libs/$project.name-$project.version-all.jar"
        }
    So missing some curly braces:
    appengine {
        stage {
            artifact = "build/libs/${project.name}-${project.version}-all.jar"
        }
    d
    3 replies · 2 participants
  • d

    Danish Ansari

    08/14/2021, 2:47 PM
    I am trying to change from
    0.0.0.0
    to
    0.0.0.0/project_name
    but while running I'm getting
    java.nio.channels.UnresolvedAddressException
    What's the correct way to change host URL?
    a
    2 replies · 2 participants
  • j

    Jonathan Hollingsworth

    08/15/2021, 3:05 AM
    Hello. What's the go to for database (specifically postgresql) connectivity in the community? I've eyeballed Exposed, but at this stage I want some far lighter weight - ideally just parameterised SQL queries, not an ORM. I also don't really want to duplicate my SQL Schema in classes, ideally. SQLDelight looks fairly promising, but the PostgreSQL support is still in development, and again it seems to solve a problem I don't have. I don't have a Java background, so perhaps there is a really basic answer I'm missing because I keep including "Kotlin" in my Google. My goal would be something like https://knexjs.org/ for Kotlin. A basic query builder that will also let me execute raw SQL with parameterised input.
    b
    ł
    +3
    19 replies · 6 participants
  • j

    jdiaz

    08/15/2021, 3:38 PM
    When using Json I see the JsonFeature removing the content-type ([here](https://github.com/ktorio/ktor/blob/main/ktor-client/ktor-client-features/ktor-cli[…]ent-json/common/src/io/ktor/client/features/json/JsonFeature.kt)), do I need to add it anywhere else? I have it in the defaultRequest but the jsonFeature is being installed after the default so it is never present
    1 reply · 1 participant
  • s

    Stylianos Gakis

    08/15/2021, 10:15 PM
    I’m using kotlinx.serialization, and when I receive a JSON object that has some unknown keys to my model a 500 is sent back automatically. I don’t want to use
    ignoreUnknownKeys = true
    . And I am using the
    post("path") { myType: MyType -> //code }
    syntax. I could potentially change this with
    val login: Login = try {
        call.receive()
    } catch (e: SerializationException) {
        return@post call.respondWith(Response.badRequest(InvalidInput))
    }
    Or even
    val login: Login = call.receiveOrNull() ?: return@post call.respondWith(Response.badRequest(InvalidInput))
    But I don’t necessarily like this if there is an alternative. How would I deal with this? Can I create an interceptor that catches all SerializationExceptions? Something else? Is my proposed solution the only way? I really do want to use the typed version of the post() method if possible.
    c
    a
    3 replies · 3 participants
  • s

    Slackbot

    08/16/2021, 2:37 AM
    This message was deleted.
    a
    a
    3 replies · 3 participants
  • y

    Yuval Dryer

    08/16/2021, 3:51 PM
    Hi All, I'm trying to run a Ktor server on android but cannot get the static webpage to display on the browser. I've added an assets folder and place the website as a subfolder in it, The request is recognized but the path I give in the response always seems to be wrong. Any ideas what I'm doing wrong?
    a
    2 replies · 2 participants
  • p

    Piotr Krzemiński

    08/16/2021, 7:22 PM
    I've just got this confusing piece of stack trace when debugging a problem with ktor:
    io.ktor.features.CORS.respondCorsFailed(CORS.kt:604)
    It points to line 604 where CORS.kt has only 537 lines... I know it seems to be not really related to ktor, but probably Kotlin in general, but has anyone faced something similar or understands why it happens? If not, I'm going to report it as a Kotlin bug.
    1 reply · 1 participant
  • a

    Angad

    08/17/2021, 6:20 AM
    I have created a Ktor feature to retry network call in case of Unauthorized error with an updated access token. In receive pipeline, I am intercepting the before phase to change the response in case of the error. I have validated that the retried call with the new access token is being success, however the status code that I am receiving in the client side is still Unauthorized. The feature implementation looks like below:
    private fun handle(config: Config, scope: HttpClient) {
        scope.receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
            if (context.response.status == HttpStatusCode.Unauthorized) {
                val client = HttpClient(scope.engine)
                var newResponse: HttpResponse = context.response
                runCatching {
                    val accessToken = config.tokenRefreshService?.getAccessToken()
                    val requestBuilder = request {
                        url(context.request.url)
                        headers {
                            for (header in context.request.headers.names()) {
                                if (header != AUTH_TOKEN) {
                                    append(header, context.request.headers[header] ?: "")
                                } else {
                                    append(header, NetworkModule.authToken(accessToken ?: ""))
                                }
                            }
                        }
                        method = context.request.method
                        body = context.request.content
                    }
                    client.request(requestBuilder) as HttpResponse
                }.onSuccess {
                    newResponse = it
                }.onFailure {
                    newResponse = response
                }
                client.close()
                if (newResponse == context.response) {
                    proceed()
                } else {
                    proceedWith(newResponse)
                }
            }
        }
    }
    Please can someone help with this? I was expecting that by updating the subject in
    proceedWith
    it will work.
    a
    6 replies · 2 participants
  • ł

    Łukasz Bednarczyk

    08/17/2021, 6:49 AM
    How can I secure store strings like passwords in a ktor app?
    a
    m
    +2
    8 replies · 5 participants
  • j

    jmfayard

    08/18/2021, 10:19 AM
    On GitHub I've found interesting ktor projects, but none that demonstrates well how do unit and integration testing. Are you aware of something like that?
    h
    j
    5 replies · 3 participants
  • h

    Harrison

    08/19/2021, 8:15 AM
    Hi there, I am trying to get Ktor client to trigger a token refresh when getting a 401. Unfortunately the api is not setting the correct auth scheme in the response header. They are using “default” when the BearerAuthProvider expects “bearer” obviously. This prevents the token refresh logic from being run. Any ideas on a not so hacky way around this?
    r
    a
    11 replies · 3 participants
  • ł

    Łukasz Bednarczyk

    08/20/2021, 8:24 AM
    Hi 🙂 I have three modules (main, core, synchronization), and I need to DB access in core and synchronization. Should I init a connection to DB in the main module or core and synchronization modules?
    a
    2 replies · 2 participants
  • c

    codec

    08/20/2021, 5:09 PM
    what happened to
    ktor.locations
    ? why does get<Object> work, but not post<Object> not work?
    ł
    5 replies · 2 participants
  • ł

    Łukasz Bednarczyk

    08/20/2021, 7:13 PM
    I have a problem with Koin - I get the DuplicateApplicationFeatureException. I have 3 modules with installed Koin plugin/feature.
    a
    r
    3 replies · 3 participants
  • t

    thanh

    08/20/2021, 7:59 PM
    Hi 👋 does someone has a best practice for sharing code between ktor server and multiplatform client?
    :all-the-things: 1
    d
    c
    +1
    4 replies · 4 participants
  • j

    Jan

    08/20/2021, 8:20 PM
    I wanted to make a little server to share files, but I get an error when I try to go to the server.
    routing {
         static("/static") {
              staticBasePackage = "/home/pi/Raspy/"
              files("public")
         }
    }
    
    2021-08-20 22:15:54.514 [eventLoopGroupProxy-4-2] TRACE ktor.application - Failed to decode request
    java.lang.IllegalArgumentException: invalid version format: XV�PÒ�ÆICL;ÅËÊ)|$À+À/̨̩À,À0À
    URL I try: https://localhost:26666/static/public/test.txt
    a
    1 reply · 2 participants
  • t

    TheDukerChip

    08/21/2021, 6:04 AM
    Has anyone worked with rsocket + ktor in android? If so kindly point me to any references
    o
    1 reply · 2 participants
  • h

    Harrison

    08/21/2021, 2:10 PM
    I am getting “io.ktor.utils.io.charsets.MalformedInputException: Input length = 1” from client when api returns 400 and “{}” instead of a responseException. New to ktor so I might be configuring the client incorrectly
    a
    2 replies · 2 participants
  • v

    v79

    08/21/2021, 4:19 PM
    I'm new to Ktor and having a problem with receiving a post - I'm sending a really simple bit of JSON
    {"title":"AA","slug":"BB"}
    and I've got an equally simple Serialiable
    data class TestForm(val title: String, val slug: String)
    . Posting the JSON from my web page gets a 415 Unsupported Media Type error. What am I likely to have got wrong in setting up ContentNegotiation?
    1 reply · 1 participant
  • d

    Didier Villevalois

    08/21/2021, 4:59 PM
    I would need some
    ktor-io
    help. I encounter some difficulties because
    ReadByteChannel
    and
    ByteReadPacket
    don't share a common super-interface for all the
    read***
    operations. I have to read a possibly large amount X of bytes (up to 2^63-1) from a
    ReadByteChannel
    . The precise number X of bytes is read first then I wish to delegate the read of the content of those X bytes to a sub-method which have to read (in this amount of bytes) an unknown number of packets of different sizes. My problem is that
    readPacket(size: Int)
    takes an
    Int
    and not a
    Long
    (and also that may be crazy to load a possibly very large number of bytes in memory). Ideally, I would like to create as "sub-channel" with a limit (of X bytes). Any hint on how I should proceed ? (Please tell me if I am not clear enough.)
    a
    7 replies · 2 participants
  • s

    Slackbot

    08/21/2021, 5:19 PM
    This message was deleted.
    b
    1 reply · 2 participants
  • j

    Jonathan Hollingsworth

    08/22/2021, 10:36 PM
    Within the docs we have
    get("/user/{login}") {
        if (call.parameters["login"] == "admin") {
            // ...
        }
    }
    But from looking at the definition
    call
    just seems an alias for
    context
    - what is the reason for the convention that has us using
    call
    over
    context
    in this situation? (Kotlin noob, so feel free just to point me at the docs and RTFM me)
    a
    1 reply · 2 participants
  • ł

    Łukasz Bednarczyk

    08/23/2021, 12:22 PM
    [Solved] 🙂 I have a strange problem. I get:
    Response has already been sent
    io.ktor.server.engine.BaseApplicationResponse$ResponseAlreadySentException: Response has already been sent
    but only in tests and only in the situation when I call
    every { something, something } throws AnyException
    Did you have similar problem?
    a
    12 replies · 2 participants
  • a

    Anton Afanasev

    08/23/2021, 12:28 PM
    Hello, I am having some issues with new
    onUpload
    API on KMM platform. Android works fine, but iOS produce an
    InvalidMutabilityException
    .I am looking for any feedback from the community. I am using ktor = 1.6.0
    suspend fun uploadFile(
            url: String,
            byteArray: ByteArray,
            progressCallback: (Float) -> Unit
        ) {
            client.put<Unit>(url) {
                onUpload { bytesSendTotal: Long, contentLength: Long ->
                    progressCallback((bytesSendTotal / contentLength.toFloat()) * 100)
                }
                body = byteArray
            }
        }
    I call it from another class that is responsible for managing states of the uploaded object. Dispatcher:
    private val uploadDispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
    Call to the function:
    uploadDispatcher.launch { api.uploadFile(url, byteArray) { progress ->
        data = data.copy(state = Uploading(progress))
            .also(onUploadProgress)
        }
    }
    where the
    onUploadProgress
    is lambda:
    private val onUploadProgress: (Data) -> Unit,
    As mentioned above, while executing this code on iOS I am receiving an
    InvalidMutabilityException
    Looking into Ktor, it looks like the
    UploadProgressListenerAttributeKey
    marked with
    @SharedImmutable
    which makes it deeply frozen and freeze the objects it refers to. Considering that when upload progress change I need to wrap and update state sof my internal objects - how should I do that using provided
    onUpload
    API?
    i
    a
    +1
    12 replies · 4 participants
Powered by Linen
Title
a

Anton Afanasev

08/23/2021, 12:28 PM
Hello, I am having some issues with new
onUpload
API on KMM platform. Android works fine, but iOS produce an
InvalidMutabilityException
.I am looking for any feedback from the community. I am using ktor = 1.6.0
suspend fun uploadFile(
        url: String,
        byteArray: ByteArray,
        progressCallback: (Float) -> Unit
    ) {
        client.put<Unit>(url) {
            onUpload { bytesSendTotal: Long, contentLength: Long ->
                progressCallback((bytesSendTotal / contentLength.toFloat()) * 100)
            }
            body = byteArray
        }
    }
I call it from another class that is responsible for managing states of the uploaded object. Dispatcher:
private val uploadDispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
Call to the function:
uploadDispatcher.launch { api.uploadFile(url, byteArray) { progress ->
    data = data.copy(state = Uploading(progress))
        .also(onUploadProgress)
    }
}
where the
onUploadProgress
is lambda:
private val onUploadProgress: (Data) -> Unit,
As mentioned above, while executing this code on iOS I am receiving an
InvalidMutabilityException
Looking into Ktor, it looks like the
UploadProgressListenerAttributeKey
marked with
@SharedImmutable
which makes it deeply frozen and freeze the objects it refers to. Considering that when upload progress change I need to wrap and update state sof my internal objects - how should I do that using provided
onUpload
API?
i

Igor Maric

08/23/2021, 2:16 PM
Same here, I tried using even newer version but it is the same.
✅ 1
a

Aleksei Tirman [JB]

08/23/2021, 2:36 PM
@Anton Afanasev could you please share definitions for symbols in?
data = data.copy(state = Uploading(progress))
    .also(onUploadProgress)
}
a

Anton Afanasev

08/23/2021, 2:42 PM
In my code
data
is actually a mutable map:
private val dataMap = mutableMapOf<String, Data>()

@Serializable
private class Data(
    val state: Data.State = Data.State.Idle,
    val id: String? = null,
    val fileName: String,
    var byteArray: ByteArray,
    var job: Job? = null,
) {

 @Serializable
    sealed class State {
        object Idle : State()
        object Deleted : State()
        object Detached : State()
        object Presigning : State()
        data class Uploading(val progress: Float) : State()
        data class Uploaded(val downloadUrl: String) : State()
        data class Sent(val downloadUrl: String) : State()
    }
}
I am using
Data
to report changes with this object. Potentially there are can be multiple
data
objects handle in the same time.
progress
is the outcome of progressCallback that is invoked every ktor.onUpdate() and simply convert the progress to percentage amount
a

Aleksei Tirman [JB]

08/23/2021, 2:51 PM
Could you please simplify your code to make
InvalidMutabilityException
reproducible without using definitions for all those classes?
a

Anton Afanasev

08/23/2021, 2:52 PM
Sure, let me do some small demo which reproduce the issue.
Hi @Aleksei Tirman [JB] I made a small demo with downloadProgress. You can find it here. https://github.com/AfanasievAnton/Ktor-Download-POC.git Also I was wondering about
UploadProgressListenerAttributeKey
and
DownloadProgressListenerAttributeKey
in io.ktor.client.features They annotated with @SharedImmutable. Wondering if it is necessary, as apparently this is the reason why my own listener and data structure that handle onUpload/onDownload become frozen as well. And since I am trying to mutate them I got an In
InvalidMutabilityException
. Thank you in advance
a

Aleksei Tirman [JB]

08/25/2021, 8:54 AM
@Anton Afanasev thank you for the sample project. Indeed, there is no way to mutate objects in a
onDownload
lambda if those objects were defined outside of it. I've created an issue KTOR-3068 to address this problem. Unfortunately, I don't know how to work around this issue.
r

russhwolf

08/25/2021, 12:26 PM
That sample will work if you make
flag
atomic
a

Anton Afanasev

08/25/2021, 1:01 PM
@Aleksei Tirman [JB] Thanks for your response. I would like to point that this limitation is relevant for both
onDownload
and
onUpload
listeners.
@russhwolf It will work But as Ktor consumer I might have a bunch of dependencies involved in OnDownlod/OnUpload progress report. And I will have to convert all of them to atomic. Unless there are some tricks to avoid it.
r

russhwolf

08/27/2021, 1:29 PM
Yeah, the native memory model takes some getting used to. Stately has some freeze-safe data structures which can help. https://github.com/touchlab/Stately
👍 1
View count: 10