Infer coroutine effects automatically
This commit is contained in:
parent
bac1183593
commit
5b30e49486
15 changed files with 339 additions and 103 deletions
14
README.md
14
README.md
|
|
@ -33,7 +33,7 @@ the semantic Type-to-Go mapping turns a class such as `User` into `*User`.
|
|||
- Gotlin classes are reference types by default; `*` is only needed for external Go pointer types
|
||||
- named external Go struct construction, for example `http.Client(timeout = 3 * time.second)`
|
||||
- top-level embedded resources such as `@embed("assets/*") val assets: embed.FS`
|
||||
- structured coroutines with `suspend fun`, `runBlocking`, `coroutineScope`, `launch`, `async`, `await`, `delay`, `withTimeout`, and `isActive`
|
||||
- inferred structured coroutine effects with `runBlocking`, `coroutineScope`, `launch`, `async`, `await`, `delay`, `withTimeout`, `isActive`, and `coroutineContext`
|
||||
|
||||
## Example
|
||||
|
||||
|
|
@ -282,8 +282,18 @@ sibling coroutine contexts. The removed `worker`, bare `go`, and channel
|
|||
`select` forms are not valid Gotlin syntax; use coroutine scopes, `delay`, and
|
||||
explicit channel `read()`/`send()` operations.
|
||||
|
||||
Coroutine effects are inferred through the call graph. Functions that directly
|
||||
or transitively use coroutine operations receive a hidden scope parameter and
|
||||
can only be called from an ambient coroutine scope. `runBlocking` establishes a
|
||||
scope boundary, so neither a `suspend` modifier nor manually threaded context is
|
||||
needed.
|
||||
|
||||
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.
|
||||
|
||||
```kotlin
|
||||
suspend fun load(): Int {
|
||||
fun load(): Int {
|
||||
delay(10)
|
||||
return 42
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue