kp-callback-bridging
Installation
SKILL.md
One-line summary
Wrap a callback-based API in suspendCancellableCoroutine { … } so callers can use it as an idiomatic suspend fun — and the wrapper deregisters the callback when the coroutine is cancelled.
When to use this skill
- Wrapping a third-party library that uses callbacks / listeners (Java SDKs, network clients, hardware APIs).
- Bridging an Android API (
OnClickListener,LocationListener, sensor callbacks) into a coroutine API. - Converting a one-shot future-style API (
CompletableFuture,ListenableFuture) into asuspend fun. - Turning a polling/event loop into a
Flow(where each emission comes from a callback).
When NOT to use this skill
- The API already returns a
Deferred, aCompletableFuture, or a coroutine — use.await()or the existing bridge function. - The callback fires many times and you want to react to every invocation — that's not a
suspend fun(one-shot); it's aFlow. UsecallbackFlow { … }instead.
Core content
suspendCancellableCoroutine<T> { cont -> … } is a coroutine builder that: