Skip to content

Instantly share code, notes, and snippets.

@lenstr
Created December 6, 2017 10:56
Show Gist options
  • Save lenstr/04d884fe648fc5827921f8c104a22046 to your computer and use it in GitHub Desktop.
Save lenstr/04d884fe648fc5827921f8c104a22046 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