@@ -10,8 +10,9 @@ import java.util.concurrent.CompletableFuture
10
10
import java.util.concurrent.TimeUnit
11
11
import javax.swing.SwingUtilities
12
12
import kotlin.coroutines.Continuation
13
- import kotlin.coroutines.ResumeInterceptor
13
+ import kotlin.coroutines.ContinuationDispatcher
14
14
import kotlin.coroutines.startCoroutine
15
+ import kotlin.coroutines.suspendCoroutine
15
16
16
17
/* *
17
18
* Run asynchronous computations based on [c] coroutine parameter
@@ -49,16 +50,16 @@ fun <T> async(
49
50
},
50
51
51
52
if (continuationWrapper != null ) {
52
- object : ResumeInterceptor {
53
- override fun <P > interceptResume (data : P , continuation : Continuation <P >): Boolean {
53
+ object : ContinuationDispatcher {
54
+ override fun <P > dispatchResume (data : P , continuation : Continuation <P >): Boolean {
54
55
continuationWrapper {
55
56
continuation.resume(data)
56
57
}
57
58
58
59
return true
59
60
}
60
61
61
- override fun interceptResumeWithException (exception : Throwable , continuation : Continuation <* >): Boolean {
62
+ override fun dispatchResumeWithException (exception : Throwable , continuation : Continuation <* >): Boolean {
62
63
continuationWrapper {
63
64
continuation.resumeWithException(exception)
64
65
}
@@ -93,7 +94,7 @@ fun asyncUI(
93
94
typealias ContinuationWrapper = (() -> Unit ) -> Unit
94
95
95
96
suspend fun <V > CompletableFuture<V>.await (): V =
96
- runWithCurrentContinuation {
97
+ suspendCoroutine {
97
98
whenComplete { value, throwable ->
98
99
if (throwable == null )
99
100
it.resume(value)
@@ -107,41 +108,41 @@ suspend fun <V> CompletableFuture<V>.await(): V =
107
108
suspend fun AsynchronousFileChannel.aRead (
108
109
buf : ByteBuffer ,
109
110
position : Long
110
- ) = runWithCurrentContinuation <Int > { c ->
111
+ ) = suspendCoroutine <Int > { c ->
111
112
this .read(buf, position, null , AsyncIOHandler (c))
112
113
}
113
114
114
115
suspend fun AsynchronousFileChannel.aWrite (
115
116
buf : ByteBuffer ,
116
117
position : Long
117
- ) = runWithCurrentContinuation <Int > { c ->
118
+ ) = suspendCoroutine <Int > { c ->
118
119
this .write(buf, position, null , AsyncIOHandler (c))
119
120
}
120
121
121
122
suspend fun AsynchronousServerSocketChannel.aAccept () =
122
- runWithCurrentContinuation <AsynchronousSocketChannel > { c ->
123
+ suspendCoroutine <AsynchronousSocketChannel > { c ->
123
124
this .accept(null , AsyncIOHandler (c))
124
125
}
125
126
126
127
suspend fun AsynchronousSocketChannel.aConnect (
127
128
socketAddress : SocketAddress
128
- ) = runWithCurrentContinuation <Unit > { c ->
129
+ ) = suspendCoroutine <Unit > { c ->
129
130
this .connect(socketAddress, null , AsyncVoidIOHandler (c))
130
131
}
131
132
132
133
suspend fun AsynchronousSocketChannel.aRead (
133
134
buf : ByteBuffer ,
134
135
timeout : Long = 0L,
135
136
timeUnit : TimeUnit = TimeUnit .MILLISECONDS
136
- ) = runWithCurrentContinuation <Int > { c ->
137
+ ) = suspendCoroutine <Int > { c ->
137
138
this .read(buf, timeout, timeUnit, null , AsyncIOHandler (c))
138
139
}
139
140
140
141
suspend fun AsynchronousSocketChannel.aWrite (
141
142
buf : ByteBuffer ,
142
143
timeout : Long = 0L,
143
144
timeUnit : TimeUnit = TimeUnit .MILLISECONDS
144
- ) = runWithCurrentContinuation <Int > { c ->
145
+ ) = suspendCoroutine <Int > { c ->
145
146
this .write(buf, timeout, timeUnit, null , AsyncIOHandler (c))
146
147
}
147
148
0 commit comments