Skip to content

Commit

Permalink
remove extra code bits from JzzMidiAccess.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Aug 15, 2024
1 parent 73db949 commit 4d8afab
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions ktmidi/src/jsMain/kotlin/dev/atsushieno/ktmidi/JzzMidiAccess.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package dev.atsushieno.ktmidi

import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlin.js.Promise

private external fun require(module: String): dynamic


private suspend fun <T> Promise<T>.await(): T = suspendCoroutine { cont ->
then({ cont.resumeWith(it.unsafeCast<Result<T>>()) }, { cont.resumeWithException(it) })
}

// FIXME: we should also create JzzMidi2Access which is based on "JZZ.UMP" ...

class JzzMidiAccess private constructor(val useSysex: Boolean, private val jzz: dynamic) : MidiAccess() {
Expand All @@ -20,7 +11,7 @@ class JzzMidiAccess private constructor(val useSysex: Boolean, private val jzz:
companion object {
// We avoid exposing mismatches around suspend functions within this class itself by
// leaving asynchronous parts out of the class.
suspend fun create(useSysex: Boolean) : JzzMidiAccess {
fun create(useSysex: Boolean) : JzzMidiAccess {
val jzz = require("jzz") (useSysex)
return JzzMidiAccess(useSysex, jzz)
}
Expand Down

0 comments on commit 4d8afab

Please sign in to comment.