Inject ambient context into Go calls

This commit is contained in:
pavel 2026-08-27 22:31:10 +02:00
commit 5085ae51aa
8 changed files with 112 additions and 9 deletions

View file

@ -304,6 +304,21 @@ 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.
For conventional Go APIs whose first parameter is `context.Context`, Gotlin
normally injects that ambient context automatically when the argument is
omitted:
```kotlin
fun command(): *exec.Cmd {
return exec.commandContext("date")
}
```
The function becomes contextually effectful and lowers to
`exec.CommandContext(gotlinScope.Context(), "date")`. Passing an explicit
context remains supported and suppresses injection, which is important for HTTP
request contexts and deliberately detached work.
```kotlin
fun load(): Int {
delay(10)