@@ -111,28 +111,6 @@ public actual suspend fun <T> withContext(
111
111
completion.getResult()
112
112
}
113
113
114
- /* *
115
- * Runs new coroutine with the private event loop until its completion.
116
- * This function should not be used from coroutine. It is designed to bridge regular code
117
- * to libraries that are written in suspending style, to be used in `main` functions and in tests.
118
- *
119
- * The default [CoroutineDispatcher] for this builder in an implementation of [EventLoop] that processes continuations
120
- * in this blocked thread until the completion of this coroutine.
121
- * See [CoroutineDispatcher] for the other implementations that are provided by `kotlinx.coroutines`.
122
- *
123
- * @param context context of the coroutine. The default value is an implementation of [EventLoop].
124
- * @param block the coroutine code.
125
- * @suppress JS Platform: **This is unstable API and it is subject to change.**
126
- */
127
- public fun <T > runBlocking (context : CoroutineContext = EmptyCoroutineContext , block : suspend CoroutineScope .() -> T ): T {
128
- val eventLoop = if (context[ContinuationInterceptor ] == null ) BlockingEventLoop () else null
129
- val newContext = newCoroutineContext(context + (eventLoop ? : EmptyCoroutineContext ))
130
- val coroutine = BlockingCoroutine <T >(newContext, privateEventLoop = eventLoop != null )
131
- coroutine.initParentJob(newContext[Job ])
132
- block.startCoroutine(coroutine, coroutine)
133
- return coroutine.joinBlocking()
134
- }
135
-
136
114
// --------------- implementation ---------------
137
115
138
116
private open class StandaloneCoroutine (
@@ -170,38 +148,4 @@ private class RunCompletion<in T>(
170
148
get() = true
171
149
}
172
150
173
- private class BlockingCoroutine <T >(
174
- parentContext : CoroutineContext ,
175
- private val privateEventLoop : Boolean
176
- ) : AbstractCoroutine<T>(parentContext, true ) {
177
- private val eventLoop: EventLoop ? = parentContext[ContinuationInterceptor ] as ? EventLoop
178
-
179
- init {
180
- if (privateEventLoop) require(eventLoop is BlockingEventLoop )
181
- }
182
-
183
- fun joinBlocking (): T {
184
- while (true ) {
185
- val delay = eventLoop?.processNextEvent() ? : Double .MAX_VALUE
186
- if (isCompleted) break
187
- if (delay > 0 ) {
188
- throw IllegalStateException (" JS thread cannot be blocked, " +
189
- " runBlocking { ... } cannot be waiting for its completion with timeout" )
190
- }
191
- }
192
- // process queued events (that could have been added after last processNextEvent and before cancel
193
- if (privateEventLoop) (eventLoop as BlockingEventLoop ).apply {
194
- // We exit the "while" loop above when this coroutine's state "isCompleted",
195
- // Here we should signal that BlockingEventLoop should not accept any more tasks
196
- isCompleted = true
197
- shutdown()
198
- }
199
- // now return result
200
- val state = this .state
201
- (state as ? CompletedExceptionally )?.let { throw it.exception }
202
- @Suppress(" UNCHECKED_CAST" )
203
- return state as T
204
- }
205
- }
206
-
207
151
0 commit comments