patternsobserver

Observer Pattern (Callbacks) pattern for C development

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 4, 2026

When & Why to Use This Skill

This Claude skill provides a standardized implementation of the Observer Pattern (Callbacks) specifically tailored for C development. It enables a decoupled, event-driven architecture by allowing objects to register for events and receive notifications via callback function pointers with associated context, improving code maintainability and scalability in C-based systems.

Use Cases

  • Streaming Data Processing: Notifying a REPL or UI in real-time as response chunks arrive from an LLM client or network stream.
  • System Signal Management: Handling OS-level signals, such as terminal resizing (SIGWINCH), to trigger UI updates or layout recalculations.
  • Asynchronous Task Monitoring: Tracking the progress and completion of background tasks or external tool executions through event notifications.
  • Reactive Database Integration: Implementing notification systems that alert the application layer when specific database changes or updates occur.
namepatterns/observer
descriptionObserver Pattern (Callbacks) pattern for C development

Observer Pattern (Callbacks)

Objects register interest in events and get notified when they occur. In C, implemented as callback function pointers with context.

ikigai Application

Streaming chunks: LLM client notifies REPL as response chunks arrive:

typedef void (*chunk_callback_t)(void *ctx, const char *chunk, size_t len);
res_t ik_llm_stream(client, messages, on_chunk, user_ctx);

Terminal resize: Signal handler notifies REPL of SIGWINCH.

Future uses:

  • Database change notifications
  • Tool execution progress
  • Background task completion

Convention: Always pair callback function pointer with void *user_ctx parameter.