Add expression functions with context boundaries
This commit is contained in:
parent
5085ae51aa
commit
773c34f3f4
18 changed files with 391 additions and 52 deletions
13
README.md
13
README.md
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue