@gildor so far i have only seen coroutinecontext used upstream in the stdlib to define the main contexts.
iiuc context is as close to threadlocal as kotlin will have for coroutines. as mentioned i saw no coroutinecontext usages in github at all. no parser mailboxes, no database transactions, no device drivers, no DI examples.
coroutine contexts are not identical to threadlocals, the graph of instance applications of one pair supplying to its contexts can be many-to-many fanout. unless I am wrong about this.
so lets take a usecase:
I have a 55gigabyte file, and i want bytebuffers to occupy MAXINT regions with mmap. i can cheaply create a base coroutine context with
File + Channel +metadata
keys and then for each mmap region i can add the
ByeteBuffer + readOrWrite
element state.
in combination with sealed class hierarchies it looks like context elements provide traits per context.
according to
https://stackoverflow.com/questions/8457505/understanding-traits-in-kotlin traits were already a feature that was removed from early kotlin.