more ios/macos targets implementation
This commit is contained in:
1 parent
87a0c14b85
commit
fa87a0f611
19 files changed
+475
-30
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package net.sergeych.synctools
|
||||
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
|
||||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
actual class WaitHandle {
|
||||
private val channel = Channel<Unit>()
|
||||
actual fun await(milliseconds: Long): Boolean {
|
||||
return runBlocking {
|
||||
try {
|
||||
if( milliseconds > 0) {
|
||||
withTimeout(milliseconds) {
|
||||
channel.receive()
|
||||
true
|
||||
}
|
||||
}
|
||||
else {
|
||||
channel.receive()
|
||||
true
|
||||
}
|
||||
}
|
||||
catch(_: TimeoutCancellationException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual fun wakeUp() {
|
||||
runBlocking { channel.send(Unit) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user