Skip to content

refactor: threadsafe callbacks#108

Merged
ahmad-kemsan merged 3 commits intomasterfrom
huzaif/threadsafe-callbacks
Mar 24, 2026
Merged

refactor: threadsafe callbacks#108
ahmad-kemsan merged 3 commits intomasterfrom
huzaif/threadsafe-callbacks

Conversation

@mir-huzaif
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the callback mechanism to be thread-safe by replacing the Napi::AsyncWorker pattern with Napi::ThreadSafeFunction. The changes consolidate callback handling into a single CallbackWrapper class and add mutex protection for callback map operations.

Key Changes:

  • Replaced AsyncWorker-based callbacks with ThreadSafeFunction for proper thread-safe callback invocation
  • Unified CallbackWrapper and ReleaseUpdateCallbackWrapper into a single polymorphic CallbackWrapper class
  • Added mutex protection for callback map modifications during registration
  • Implemented proper cleanup of existing callbacks before replacing them

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/native/CallbackWrapper.h Complete refactor from AsyncWorker to ThreadSafeFunction pattern with data structures for different callback types
src/native/main.cpp Added mutex for callback map protection, updated callback registration functions with cleanup logic, modified callback invocation to use new Call() methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/native/main.cpp
Comment thread src/native/CallbackWrapper.h
Comment thread src/native/CallbackWrapper.h
Comment thread src/native/main.cpp Outdated
Comment thread src/native/main.cpp Outdated
Comment thread src/native/main.cpp Outdated
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@ahmad-kemsan ahmad-kemsan merged commit 2945349 into master Mar 24, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants