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 a suspend 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, a CompletableFuture, 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 a Flow. Use callbackFlow { … } instead.

Core content

suspendCancellableCoroutine<T> { cont -> … } is a coroutine builder that:

Installs
1
GitHub Stars
1
First Seen
Jul 13, 2026
kp-callback-bridging — yonatankarp/software-design-skills