Marc Knaup
06/12/2019, 12:26 AMHttpClient in a Worker (background thread) on native 🙂Marc Knaup
06/12/2019, 12:26 AMTransferMode.UNSAFE to move(!) the HttpClient instance to your Worker. Unless you create it directly within the worker in which case this is not necessary. In both cases it is stored in an @ThreadLocal variable.
worker.execute(TransferMode.UNSAFE, { HttpClient(Ios) }) { httpClient -> threadLocalHttpClient = httpClient }Marc Knaup
06/12/2019, 12:26 AMHttpClient calls inside your Worker.
GlobalScope.launch(Dispatchers.Unconfined) {
// use HttpClient
}Marc Knaup
06/12/2019, 12:26 AMbody = TextContent(
text = someJson,
contentType = ContentType.Application.Json
)
->
body = ByteArrayContent(
bytes = someJson.toUtf8(),
contentType = ContentType.Application.Json
)Marc Knaup
06/12/2019, 1:02 AMHttpClient instance on a non-main thread until this is fixed:
https://github.com/ktorio/ktor/issues/1183
There may be more of such issue though.Marc Knaup
06/12/2019, 1:48 AMNSURLSession responds on the main thread and the coroutine continues on that thread due to Unconfined 😞
Is there a better way of getting the coroutine execution back into the Worker rather than using worker.execute(TransferMode.UNSAFE, …)?e5l
06/13/2019, 12:41 PMatomicfu primitives and it can't be solved on ktor side for now.