Add expression functions with context boundaries

This commit is contained in:
pavel 2026-08-27 23:05:49 +02:00
commit 773c34f3f4
18 changed files with 391 additions and 52 deletions

View file

@ -304,6 +304,19 @@ Use `coroutineContext()` only at Go interop boundaries that require a
`context.Context`; it returns the ambient scope context without exposing it in
the Gotlin function signature.
HTTP handlers can establish a request-scoped ambient context with an
expression-bodied function:
```kotlin
fun handle(request: *http.Request) = withContext(request.context()) {
service.processRequest()
}
```
`withContext` is a structured boundary. It waits for children, propagates
failures, and, when nested, combines cancellation from the parent coroutine and
the supplied Go context.
For conventional Go APIs whose first parameter is `context.Context`, Gotlin
normally injects that ambient context automatically when the argument is
omitted: