Question about `ktor` on App Engine standard. What...
# ktor
r
Question about
ktor
on App Engine standard. What thread are requests dispatched on ? Because trying to use Any
AppEngine
APIs give me an exception. For e.g.
Copy code
get("/test") {
        val executor = Executors.newCachedThreadPool(ThreadManager.currentRequestThreadFactory())
        val scope = CoroutineScope(executor.asCoroutineDispatcher())
        scope.launch {
            val oauthScope = "<scope>"
            val accessToken = AppIdentityServiceFactory.getAppIdentityService().getAccessToken(listOf(oauthScope))
            call.respondText {
                accessToken.accessToken
            }
        }
    }
Copy code
java.lang.NullPointerException: Current thread is not associated with any request and is not a background thread
        at com.google.appengine.api.ThreadManager.getCurrentEnvironmentOrThrow(ThreadManager.java:106)
        at com.google.appengine.api.ThreadManager.currentRequestThreadFactory(ThreadManager.java:47)
        at androidx.snapshots.RequestHandlersKt$main$3.invokeSuspend(RequestHandlers.kt:29)
        at androidx.snapshots.RequestHandlersKt$main$3.invoke(RequestHandlers.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:273)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:141)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:161)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
        at io.ktor.routing.Routing.executeResult(Routing.kt:147)
        at io.ktor.routing.Routing.interceptor(Routing.kt:34)