Skip to content

Commit b6eca2a

Browse files
committed
Make EventLoop internal, @JvmName("from") for ExecutorService.asCoroutineDispatcher
1 parent 7fb590d commit b6eca2a

File tree

4 files changed

+4
-55
lines changed

4 files changed

+4
-55
lines changed

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,32 +235,15 @@ public abstract interface class kotlinx/coroutines/DisposableHandle {
235235
public abstract fun dispose ()V
236236
}
237237

238-
public abstract interface class kotlinx/coroutines/EventLoop : kotlin/coroutines/ContinuationInterceptor {
239-
public abstract fun processNextEvent ()J
240-
}
241-
242-
public final class kotlinx/coroutines/EventLoop$DefaultImpls {
243-
public static fun fold (Lkotlinx/coroutines/EventLoop;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
244-
public static fun get (Lkotlinx/coroutines/EventLoop;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
245-
public static fun minusKey (Lkotlinx/coroutines/EventLoop;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
246-
public static fun plus (Lkotlinx/coroutines/EventLoop;Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
247-
public static fun releaseInterceptedContinuation (Lkotlinx/coroutines/EventLoop;Lkotlin/coroutines/Continuation;)V
248-
}
249-
250-
public final class kotlinx/coroutines/EventLoopKt {
251-
public static final fun EventLoop (Ljava/lang/Thread;Lkotlinx/coroutines/Job;)Lkotlinx/coroutines/EventLoop;
252-
public static synthetic fun EventLoop$default (Ljava/lang/Thread;Lkotlinx/coroutines/Job;ILjava/lang/Object;)Lkotlinx/coroutines/EventLoop;
253-
}
254-
255238
public abstract class kotlinx/coroutines/ExecutorCoroutineDispatcher : kotlinx/coroutines/CoroutineDispatcher, java/io/Closeable {
256239
public fun <init> ()V
257240
public abstract fun close ()V
258241
public abstract fun getExecutor ()Ljava/util/concurrent/Executor;
259242
}
260243

261244
public final class kotlinx/coroutines/ExecutorsKt {
262-
public static final fun asCoroutineDispatcher (Ljava/util/concurrent/ExecutorService;)Lkotlinx/coroutines/ExecutorCoroutineDispatcher;
263245
public static final fun from (Ljava/util/concurrent/Executor;)Lkotlinx/coroutines/CoroutineDispatcher;
246+
public static final fun from (Ljava/util/concurrent/ExecutorService;)Lkotlinx/coroutines/ExecutorCoroutineDispatcher;
264247
}
265248

266249
public abstract interface annotation class kotlinx/coroutines/ExperimentalCoroutinesApi : java/lang/annotation/Annotation {

core/kotlinx-coroutines-core/src/EventLoop.kt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package kotlinx.coroutines
66

77
import kotlinx.atomicfu.*
88
import kotlinx.coroutines.internal.*
9-
import java.util.concurrent.locks.*
109
import kotlin.coroutines.*
1110

1211
/**
@@ -18,8 +17,7 @@ import kotlin.coroutines.*
1817
*
1918
* @suppress **This an internal API and should not be used from general code.**
2019
*/
21-
@InternalCoroutinesApi // todo: review KDoc references to this interface
22-
public interface EventLoop: ContinuationInterceptor {
20+
internal interface EventLoop: ContinuationInterceptor {
2321
/**
2422
* Processes next event in this event loop.
2523
*
@@ -31,28 +29,6 @@ public interface EventLoop: ContinuationInterceptor {
3129
public fun processNextEvent(): Long
3230
}
3331

34-
/**
35-
* Creates a new event loop that is bound the specified [thread] (current thread by default) and
36-
* stops accepting new events when [parentJob] completes. Every continuation that is scheduled
37-
* onto this event loop unparks the specified thread via [LockSupport.unpark].
38-
*
39-
* The main event-processing loop using the resulting `eventLoop` object should look like this:
40-
* ```
41-
* while (needsToBeRunning) {
42-
* if (Thread.interrupted()) break // or handle somehow
43-
* LockSupport.parkNanos(eventLoop.processNextEvent()) // event loop will unpark
44-
* }
45-
* ```
46-
*
47-
* @suppress **This an internal API and should not be used from general code.**
48-
*/
49-
@Suppress("FunctionName")
50-
@InternalCoroutinesApi
51-
public fun EventLoop(thread: Thread = Thread.currentThread(), parentJob: Job? = null): EventLoop =
52-
EventLoopImpl(thread).apply {
53-
if (parentJob != null) initParentJob(parentJob)
54-
}
55-
5632
private val DISPOSED_TASK = Symbol("REMOVED_TASK")
5733

5834
// results for scheduleImpl
@@ -362,17 +338,6 @@ internal abstract class ThreadEventLoop(
362338
}
363339
}
364340

365-
private class EventLoopImpl(thread: Thread) : ThreadEventLoop(thread) {
366-
private var parentJob: Job? = null
367-
368-
override val isCompleted: Boolean get() = parentJob?.isCompleted == true
369-
370-
fun initParentJob(parentJob: Job) {
371-
require(this.parentJob == null)
372-
this.parentJob = parentJob
373-
}
374-
}
375-
376341
internal class BlockingEventLoop(thread: Thread) : ThreadEventLoop(thread) {
377342
@Volatile
378343
public override var isCompleted: Boolean = false

core/kotlinx-coroutines-core/src/Executors.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public abstract class ExecutorCoroutineDispatcher: CoroutineDispatcher(), Closea
3434
/**
3535
* Converts an instance of [ExecutorService] to an implementation of [ExecutorCoroutineDispatcher].
3636
*/
37+
@JvmName("from") // this is for a nice Java API, see issue #255
3738
public fun ExecutorService.asCoroutineDispatcher(): ExecutorCoroutineDispatcher =
3839
// we know that an implementation of Executor.asCoroutineDispatcher actually returns a closeable one
3940
(this as Executor).asCoroutineDispatcher() as ExecutorCoroutineDispatcher

core/kotlinx-coroutines-core/src/test_/TestCoroutineContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class TestCoroutineContext(private val name: String? = null) : CoroutineContext
193193
private fun processNextEvent(): Long {
194194
val current = queue.peek()
195195
if (current != null) {
196-
/** Automatically advance time for [EventLoop]-callbacks */
196+
// Automatically advance time for EventLoop callbacks
197197
triggerActions(current.time)
198198
}
199199
return if (queue.isEmpty) Long.MAX_VALUE else 0L

0 commit comments

Comments
 (0)