Skip to content

Instantly share code, notes, and snippets.

@lenstr
Created December 6, 2017 10:57
Show Gist options
  • Save lenstr/1af5727cbe01ce0b5855b693f9871019 to your computer and use it in GitHub Desktop.
Save lenstr/1af5727cbe01ce0b5855b693f9871019 to your computer and use it in GitHub Desktop.
suspend fun uvClose(handle: CPointer<uv_handle_t>): Unit = suspendCoroutine { cont ->
handle.pointed.data = StableRef.create(cont).asCPointer()
uv_close(handle, staticCFunction { handle: CPointer<uv_handle_t>? ->
handle ?: return@staticCFunction
val data = handle.pointed.data ?: return@staticCFunction
val contRef = data.asStableRef<Continuation<Unit>>()
contRef.get().resume(Unit)
contRef.dispose()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment