$ show Wulf/nodehun
Nodehun is a Node.js native addon that provides bindings to the Hunspell spell checking library. It exposes Hunspell functionality through both synchronous and asynchronous APIs, enabling spell checking, suggestions, morphological analysis, and runtime dictionary management in Node.js applications. The architecture centers around a thread-safe Hunspell context using read-write locks to allow concurrent read operations, with asynchronous workers offloading intensive computations to libuv's thread pool. Key entry points include the Nodehun class initialization in src/index.cc and the async worker implementations in src/Async/. The system relies on the bundled Hunspell library (built from source) and N-API for Node.js version stability.
The LLM identified 2 files worth highlighting for reuse:
Implements a thread-safe wrapper for Hunspell instances using a read-write lock (pthread_rwlock). Allows concurrent spell checking operations (reads) while ensuring exclusive access for dictionary modifications (writes). This pattern solves the fundamental thread-safety limitation of the underlying Hunspell library, enabling safe usage in Node.js's multi-threaded environment without blocking the event loop during read-heavy workloads.
Defines the base asynchronous worker class that leverages libuv's thread pool via uv_queue_work to offload Hunspell operations. Specific workers (SpellWorker, SuggestWorker, etc.) inherit from this base to implement work execution and result handling. This pattern prevents blocking the Node.js event loop during CPU-intensive spell checking tasks and provides a reusable structure for adding new asynchronous operations with consistent error handling and callback management.