new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

ipc core

3 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

C++ to JavaScript callback pattern with threadsafe functions

To call JavaScript from C++ running in a separate thread, use napi_create_threadsafe_function to create a threadsafe function. Store it as napi_threadsafe_function member variable. When C++ needs to invoke a callback, create a data structure (CallbackData) containing event type and payload, then call napi_call_threadsafe_function(tsfn_, data, napi_tsfn_blocking). The callback finalization function executes on the JavaScript thread and can safely invoke JavaScript functions. Always release the threadsafe function in destructor using napi_release_threadsafe_function(tsfn_, napi_tsfn_release) or napi_tsfn_abort to prevent hangs.

N-API threadsafe function for callbacks across threads

Use napi_create_threadsafe_function to safely pass callbacks between native threads and the JavaScript event loop. This creates a thread-safe wrapper that can be called from any thread and safely invokes JavaScript callbacks. Release with napi_release_threadsafe_function using napi_tsfn_release for normal cleanup or napi_tsfn_abort to cancel pending calls. Call threadsafe functions with napi_call_threadsafe_function(tsfn, data, napi_tsfn_blocking).

EventEmitter pattern for native addon events

Extend EventEmitter in JavaScript wrapper class to provide event support. Forward native events from addon.on() calls to this.emit() for JavaScript consumers. Example: this.addon.on('todoAdded', (payload) => { this.emit('todoAdded', data) }). This creates a unified event interface.

Give your agent this brain