Skip to content

How to redefine CoroutineContext #2257

Description

@cbxp

When using coroutine router, it has a final coroutineScope inside, which is created lazily from worker.

However, there seems to be no easy way to add a CoroutineContext to the scope, e.g. MDCContext from
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-slf4j/index.html

Could there be a setter for coroutineScope, to enable code like this:

coroutine {
  coroutineScope += MDCContext()

  // routes here
}

or another option is to add scope to CouroutineRouter constructor:

coroutine(context = MDCContext()) {
  // routes here
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions