Skip to content

Commit 76865f8

Browse files
committed
Use a thread instead of Executors.newSingleThreadExecutor() to let the JVM shutdown after the execution. Update README.md
1 parent c02c58b commit 76865f8

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ High Level API depends on [Keyboard][4] which is a wrapper around the [NativeKey
151151
keyboard.play(records, speedFactor = 1.25)
152152
```
153153

154-
__Note: In Kotlin/Native environment, the `Keyboard.dispose()` must be called in order to avoid memory leaks (when process is alive, but the Keyboard instance is no longer referenced).__
155-
156154
## Contributing and future plans
157155

158156
The Github dicussions are open! Be sure to show your existence, say hi! and share if you have any upcoming ideas :)

keyboard/src/jvmMain/kotlin/com/github/animeshz/keyboard/JvmKeyboardHandler.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import com.github.animeshz.keyboard.entity.Key
44
import com.github.animeshz.keyboard.events.KeyEvent
55
import com.github.animeshz.keyboard.events.KeyState
66
import kotlinx.coroutines.ExperimentalCoroutinesApi
7-
import java.util.concurrent.Executors
7+
import kotlin.concurrent.thread
88

99
@ExperimentalCoroutinesApi
1010
@ExperimentalKeyIO
1111
internal object JvmKeyboardHandler : NativeKeyboardHandlerBase() {
12-
private val ioExecutor = Executors.newSingleThreadExecutor()
13-
1412
init {
1513
NativeUtils.loadLibraryFromJar("KeyboardKt")
1614
if (nativeInit() != 0) {
@@ -35,7 +33,7 @@ internal object JvmKeyboardHandler : NativeKeyboardHandlerBase() {
3533
external override fun isScrollLockOn(): Boolean
3634

3735
override fun startReadingEvents() {
38-
ioExecutor.execute {
36+
thread {
3937
val code = nativeStartReadingEvents()
4038
if (code != 0) {
4139
// Cannot throw, execute will consume it

0 commit comments

Comments
 (0)