I'm almost certain I know the answer to this, but ...
# coroutines
n
I'm almost certain I know the answer to this, but just in case: Is it possible to specify the type of CoroutineScope for a given CoroutineDispatcher or a CoroutineContext? For example, a context/dispatcher for a database that will pass the connection to the scope?
e
Sorry, but I don’t understand your question. What are you trying to achieve?
n
Something like..
Copy code
launch(DB) { /* here the context of the database is automatically available */ }
g
You can lookup context inside of coroutine scope, context is available inside of coroutine
g
yeah, so statically no, but at runtime yes. You could then provide your own:
Copy code
//damn these narrow thread columns...
fun launchInDBContext(
    moreContext: CoroutineContext, 
    block: suspend DBScope.() -> Unit): Job{
  return launch(DBContext + moreContext){
    val directScope = this;
    val dbContext = directScope[DBContext.Key]
    val modifiedDBScope = DBScope(directScope, dbContext)
    newScope.block()
  }
}
you can probably even make that
inline
with
crossinline
on the lambda.