Inject ambient context into Go calls
This commit is contained in:
parent
acb42a5702
commit
5085ae51aa
8 changed files with 112 additions and 9 deletions
15
README.md
15
README.md
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue