Not really. I'm trying to do that on a background thread (using coroutines-native-mt), but can't access FileSystem.SYSTEM on that thread:
Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
...nor pass it from one thread to another (frozen mutation etc).
I kinda managed to do that with something like (writing pseudocode from memory):
withContext(Dispatchers.Main){
FileSystem.SYSTEM.write(path){
httpClient.get<HttpStatement>...{
write(buffer)
}
}
}
And it created the file and allocated bytes, but something froze and I'm not even sure what is done on what thread here.
@jw is it supposed to work on background thread in kotlin native? If so, how can I create the BufferedSink from FileSystem and then do the writing on bg thread? Something like
Okio.buffer(FileSystem.SYSTEM.sink(path))
only seems to be doable on main thread.