Skip to content

Convert CoroutineContext into Executor #1450

Closed
@ZakTaccardi

Description

@ZakTaccardi

I have to use an API that accepts an Executor as a parameter. How can I create an Executor that is backed by Dispatchers.Default?

Can a CoroutineDispatcher.asExecutor(): Executor function be added to support this use case?

fun externalApi(executor: Executor)

fun example() {
  val executor: Executor = Dispatchers.Default.asExecutor()
  
  externalApi(executor)
}

Even better would be a fun CoroutineContext.asExecutor(): Executor function. I would imagine if the receiver CoroutineContext does not have a ContinuationInterceptor, this function would throw.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions